-, , , :
PHP - . :
class MyClass {
public $foo = 'bar';
}
$Instance = new MyClass();
echo $Instance->foo;
, "", . :
class MyOverloadedClass {
public function __get($variable) {
return $variable == 'foo' ? 'bar' : '';
}
}
$Instance = new MyOverloadedClass();
echo $Instance->foo;
, MyOverloadedClass:: $foo , __ge , ( "foo" ). __get , foo "bar"
PHP. , , , . : exit, die, print, echo, isset empty.
isset() - . __isset, , , - isset . empty() true , , E_NOTICE. :
: empty() , __get(), IF ONLY, __isset(), true :
empty () will not call your overloaded __get () method. It will look in the class definition to find out if this parameter exists. If so, it will evaluate whether it is empty or not. However, accessing the parameters of the undefined class causes an error. In my first example, I would throw an error by querying the string $ Instance-> bar, because it does not exist. This is the same error you would get if you asked
empty( $Instance->foo );
In the second example. Hope this helps.
For more information on how to apply this to functions or setting variables, see the page you mentioned.