Setting 'MYBASEVAR1' to 'Hello' Setting 'MYBASEVAR2' to 'World' Setting 'MYEXTVAR1' to 'Google' Setting 'MYEXTVAR2' to 'Yahoo' Setting 'MYEXT2VAR1' to 'Zebra' Setting 'MYEXT2VAR2' to 'Tiger'
When reading/writing data from inaccessible properties the magic methods __get() and __set() are called. Is this the same when accessing the property statically?
Property overloading only works in object context. These magic methods will not be triggered in static context. Therefore these methods should not be declared static. As of PHP 5.3.0, a warning is issued if one of the magic overloading methods is declared static.
MyStaticBaseClass::MYVARNAME = 'Hello';
ERROR
echo MyStaticBaseClass::MYVARNAME;
ERROR
MyStaticBaseClass::getAll();
Array ( [MYBASEVAR1] => Hello [MYBASEVAR2] => World [MYEXTVAR1] => Google [MYEXTVAR2] => Yahoo [MYEXT2VAR1] => Zebra [MYEXT2VAR2] => Tiger )
MyStaticExtendedClass::getAll();
Array ( [MYBASEVAR1] => Hello [MYBASEVAR2] => World [MYEXTVAR1] => Google [MYEXTVAR2] => Yahoo [MYEXT2VAR1] => Zebra [MYEXT2VAR2] => Tiger )
MyStaticExtendedClass2::getAll();
Array ( [MYBASEVAR1] => Hello [MYBASEVAR2] => World [MYEXTVAR1] => Google [MYEXTVAR2] => Yahoo [MYEXT2VAR1] => Zebra [MYEXT2VAR2] => Tiger )
$MyExtendedInstance->getAll();
Array ( [MYBASEVAR1] => Hello [MYBASEVAR2] => World [MYEXTVAR1] => Google [MYEXTVAR2] => Yahoo [MYEXT2VAR1] => Zebra [MYEXT2VAR2] => Tiger )
echo $MyExtendedInstance->get('MYBASEVAR1');
Getting 'MYBASEVAR1' Hello
[Home]