[eluser]Unknown[/eluser]
Hi everyone, new here, used CodeIgniter for quite a while.
I'm starting a new project, ofcourse using the latest Reactor from BitBucket. I'm trying to automate process of importing the URL segments into properties of my controllers. I use magic methods in MY_Controller to make it happen. This, however, triggers the following error:
Quote:A PHP Error was encountered
Severity: Notice
Message: Indirect modification of overloaded property Test::$benchmark has no effect
Filename: core/Controller.php
Line Number: 46
Fatal error: Cannot assign by reference to overloaded object in C:\xampp\htdocs\wzr_achterkant\system\core\Controller.php on line 46
Using the following code
Code:
class MY_Controller extends CI_Controller {
private $get_params = array(); // get parameters container
protected $parameters = array('format'); // array of valid get parameters
function __construct() {
parent::__construct();
$this->_parseGetParams();
}
// magic method to set parameter
function __set($name, $value) {
if (in_array($name, $parameters)) { // if it's a valid parameter
$this->get_params[$name] = $value;
}
}
// magic method to get parameters
function __get($name) {
if (array_key_exists($name, $this->get_params)) {
return $this->get_params[$name];
}
}
function __unset($name) {
if (in_array($name, $parameters)) { // als het een geldige parameter is
unset($this->get_params[$name]);
}
}
function __isset($name) {
return isset($this->get_params[$name]);
}
// parsing of get parameters
function _parseGetParams() {
$parameters = $this->uri->ruri_to_assoc();
foreach($this->parameters as $valid_param) {
if (isset($parameters[$valid_param]) && strlen($parameters[$valid_param]) > 0) {
$this->$valid_param = $parameters[$valid_param];
}
}
}
}
The error states it fails at line 46 from the Core Controller. These are lines 41-48:
Code:
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class);
}
I believe the problem is that "$this->$var" is assigned by reference. When I comment out my "__get()" function, everything (except my overloading) works fine!
Does anyone have an idea how this would work?