Answer the question
In order to leave comments, you need to log in
PHP __get() magic method not executing, what should I do?
Hello!
I'm learning PHP, I've reached OOP, where auto video courses consider the magic methods __get () and __ set ()
The problem arose precisely with the __get () method, namely, the fact that it is not executed.
The author claims that if we refer to a non-existent property in php, then the property will be created automatically and will be displayed when accessing it.
class SomeClass{
}
$obj = new SomeClass();
$obj->param = 4;
echo $obj->param; // должно быть выведено 4
class MyClass {
function __set($n, $v){
echo $n, ":", $v;
}
function __get($n){
echo $n;
}
}
$odj = new MyClass();
$odj->param = 100;
echo $obj->param;
Answer the question
In order to leave comments, you need to log in
Всё дело в том, что вы не показываете весь код.
Указанные примеры дают совершенно одинаковый результат на PHP 5.6-7.1RC3 и HHVM 3.10-3.14: https://3v4l.org/XE8WC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question