Not sure why this works like that, but if you delete &before $thisby assigning it to a global variable, it will work.
To illustrate this, the following piece of code:
$global_obj = null;
class my_class
{
public $my_value;
public function __construct()
{
global $global_obj;
$global_obj = $this;
}
}
$a = new my_class;
$a->my_value = 5;
$global_obj->my_value = 10;
echo $a->my_value;
:
10
:
& $this: PHP 5,- PHP 5:
__constructpublic/protected/private, var properties
, , :
Strict standards: Creating default object from empty value
:
- PHP 5.3.2
E_ALL E_STRICT ()
:
Explained PHP , , , , ():
, , .
, $GLOBALS.
.
$GLOBALS , :
$global_obj = null;
class my_class
{
public $my_value;
public function __construct()
{
$GLOBALS['global_obj'] = & $this;
}
}
$a = new my_class;
$a->my_value = 5;
$global_obj->my_value = 10;
echo $a->my_value;
:
10
, ; -)
__construct :
public function __construct()
{
global $global_obj;
$global_obj = & $this;
}
...
, , global , $GLOBALS.
, :
global $var; $var =&
$GLOBALS['var'];. , $var .
: , , - ...
(, , , ... , ;-))