Current time: 03-21-2010, 06:27 AM Hello There, Guest! (LoginRegister)


 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[F] $lang-object not accessible from run_shutdown()
08-24-2008, 07:23 PM
Post: #1
[F] $lang-object not accessible from run_shutdown()
On MyBB 1.4.1 running with PHP 5.2.5 or 5.2.6 the $lang object seems to be deconstructed before run_shutdown() is called, resulting for example in the task-log displaying the execution time, but no text. Of course only afflicts installations using the PHP shutdown-functionality.

As a fix the run_shutdown() function should reconstruct the object. My idea is to change two files to do that.

a) functions.php, e.g. line 196
Code:
    // Lang object deconstructed? reconstruct
  if(!is_object($lang))
  {
    require_once MYBB_ROOT."inc/class_language.php";
    $lang = new MyLanguage;
    $lang->set_path(MYBB_ROOT."inc/languages");
    // Load language
    $lang->set_language($mybb->settings['bblanguage']);
    $lang->load("global");
    $lang->load("messages");
  }

b) class_language.php, line 125
The fix above didn't work at first, only after I changed class_language.php, function load(), line 125. Replaced two required_onces by requireds. Apparently php still knows it once loaded the files. Reading them again does no harm, so... here is the changed code:
Code:
    function load($section, $isdatahandler=false, $supress_error=false)
    {
        // Assign language variables.
        // Datahandlers are never in admin lang directory.
        if($isdatahandler === true)
        {
            $this->language = str_replace('/admin', '', $this->language);
        }
        $lfile = $this->path."/".$this->language."/".$section.".lang.php";
        
        if(file_exists($lfile))
        {
          // php-shutdown-hack Henrik Zawischa
          require $lfile;
//            require_once $lfile;
        }
        elseif(file_exists($this->path."/english/".$section.".lang.php"))
        {
          // php-shutdown-hack Henrik Zawischa
            require $this->path."/english/".$section.".lang.php";
//            require_once $this->path."/english/".$section.".lang.php";
        }
        else
        {
            if($supress_error != true)
            {
                die("$lfile does not exist");
            }
        }
        
        if(is_array($l))
        {
            foreach($l as $key => $val)
            {
                if(empty($this->$key) || $this->$key != $val)
                {
                    $this->$key = $val;
                }
            }
        }
    }

After both changes the task logging works as expected on 1.4.1 with PHP 5.2.5 and 5.2.6.

Zakkinen
Find all posts by this user
08-24-2008, 11:04 PM
Post: #2
Question RE: $lang-object not accessible from run_shutdown()
That reminds me, here's a question for the developers: why not use register_shutdown_function() for all PHP versions?

PHP Code:
// Old version of PHP, need to register_shutdown_function
if(phpversion() < '5.0.5')
{
    
$this->use_shutdown true;
    
register_shutdown_function(array(&$this"__destruct"));


Shutdown functions are first in PHP's shutdown sequence, before object destruction, so they shouldn't have the "missing object" problem, and all that dodgy "reconstruct" code in MyBB's run_shutdown() function could be deleted. Toungue

PHP Code:
// If our DB has been deconstructed already (bad PHP 5.2.0), reconstruct 

It looks like the PHP developers don't plan on changing this, and it still happens in 5.2.6...
Visit this user's website Find all posts by this user
08-26-2008, 03:38 AM
Post: #3
[F] $lang-object not accessible from run_shutdown()
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.

[Image: ryangordon.png]
My Blog - My Mods
Visit this user's website Find all posts by this user


Forum Jump: