Model::_assign_libraries() rewrites null variables in Controller |
|||
|---|---|---|---|
| Date: | 08/29/2008 | Severity: | Minor |
| Status: | Resolved | Reporter: | Maxim Guisov |
| Version: | 1.6.3 | ||
| Keywords: | |||
Description
Bad thing happen when I set some variable in controller to NULL, then load library, then see my variable === ‘’ instead of NULL.
Model::_assign_libraries() is called twice, first in Model ctr, then in CI_Loader::model(), right after model construction. When __get and __set are not defined in Model, _assign_libraries copies ‘libraries’ (actually all variables) by reference. Following code checks that ‘library’ isn’t there yet:
if ( !isset($this->$key) AND
$key != $this->_parent_name) ...
From PHP manual: isset() will return FALSE if testing a variable that has been set to NULL.
Code Sample
class MY_controller extends Controller
{
protected $_my_var = null;
}
class SomeAppController extends MY_Controller
{
public function index()
{
$this->load->model('some_model');
if ($this->_my_var === NULL)
echo '"default"';
else
echo '"'.$this->_my_var.'"';
}
}
Expected Result
“default”
Actual Result
”“
