Welcome Guest, Not a member yet? Register   Sign In
Validation in autoload PHP 4 (Fix suggested)
#1

[eluser]Seppo[/eluser]
This is an old bug... It has been reported many times, and currently it´s in the tracker with the ID 3175

The original problem is that in the view you get an empty error_string even if the validation fails.
Tracking it down, I found out that the problem was that PHP was generating a copy of the autoloaded class, so they were different in the controller class and in the loader class (where the $this variable point, inside the views).
A quick example, to show this

Code:
// system/application/config/autoload.php
$autoload['libraries'] = array('validation');

// system/application/controllers/bug3175.php
class Bug3175 extends Controller {
    function Bug3175()
    {
        parent::Controller();
    }

    function index()
    {
        $this->validation->hello_world = 'abcde';
        $this->load->view('bug3175');
    }
}

// system/application/controllers/bug3175.php
echo $this->validation->hello_world;

In PHP 4 (I´ve tested this in 4.3.9 and 4.4.7) throws a notice for the undefined variable. In PHP 5 (5.0.0, 5.1.6, 5.2.5) it prints "abcde", as expected.



After tracking this bug inside all core I´ve finally reached to system/libraries/Controller.php, on line 87. After $this->_ci_autoloader(); I´ve added
Code:
foreach (array_keys(get_object_vars($this)) as $attribute)
            {
                if (is_object($this->$attribute))
                {
                    $this->load->$attribute =& $this->$attribute;
                }
            }
which syncronize back the references between the Loader and the Controller.

PLEASE EVERYONE, test this on all PHP versions you can and submit the result, so we can finally fix this bug...


Messages In This Thread
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-16-2008, 08:05 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-17-2008, 09:59 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-17-2008, 10:01 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 03:10 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 03:38 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 04:19 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 04:25 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 01:51 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:20 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:26 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:55 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 01:37 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:41 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:43 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:44 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:59 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 03:36 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-22-2008, 04:06 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 08-30-2008, 05:42 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 08:50 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 08:54 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 09:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB