Welcome Guest, Not a member yet? Register   Sign In
Undefined property: CI_Loader::$theme after move from PHP4 -> PHP5
#1

[eluser]WanWizard[/eluser]
I've been going though my code for the last few hours, but this issue got me baffled.

I have a third party class that I use in my project. I have created a Theme.php file in my libraries directory, which loads this class, then defines the Theme class that extends this third party class:

Code:
// load the skin engine class
require_once "3rdparty/skinengine.php";

// ------------------------------------------------------------------------

class Theme extends SkinEngine {

    function Theme()
    {
        // call the parent constructor
        parent::SkinEngine();
    }
}

This library is autoloaded in the config. The 3rd party class is PHP5 proof, I use it in other (non-CI) projects without problems.

When running in PHP4 (4.3.11), I can do a $this->theme->render($template) without problems. A var_dump($this) tells me the class is instantiated just fine. When starting the exact same code in PHP5 (5.2.6), var_dump($this) tells me:

Code:
CI_Loader Object
(
    [_ci_ob_level] => 1
    [_ci_view_path] => /data/www/virtual/test/system/application/views/
    [_ci_is_php5] => 1
    [_ci_is_instance] =>
    [_ci_cached_vars] => Array
        (
        )

    [_ci_classes] => Array
        (
            [session] => session
            [theme] => theme
            [users] => users
            [dispatch] => dispatch
        )

    [_ci_loaded_files] => Array
        (
            [0] => /data/www/virtual/test/system/libraries/Session.php
            [1] => /data/www/virtual/test/system/application/libraries/Theme.php
            [2] => /data/www/virtual/test/system/application/libraries/Users.php
            [3] => /data/www/virtual/test/system/application/libraries/Dispatch.php
        )
     .....
I have the variables session, users and dispatch, which all point to their objects, but I'm missing the theme variable (hence the error message).

If I modify the Theme.php and remove the 'extends' bit, or load the original class without extending it, everything works fine.

Is this a bug in CI? In PHP5? Or (more likely) did I do something stupid?

Kind regards,
WanWizard
#2

[eluser]WanWizard[/eluser]
Fixed the problem.

Turned out that for some reason CI_BASE (in Base5.php) was instantiated twice, which ruined the result of get_instance().

Solution:
Code:
public function CI_Base()
    {
        //
        // fix to make sure second instantiation doesn't ruin
        // the superobject pointer!
        //
        if ( ! isset(self::$instance) )
        {
            self::$instance =& $this;
        }
    }
which makes sure it is NEVER overwritten once defined. Now I only have to find the 'some reason'... Wink




Theme © iAndrew 2016 - Forum software by © MyBB