The problem is that the __get
method is not reentrant, so when you access $reader->cost
it is called for the first time and will call Reader::getCost()
, but then $this->cost
forces PHP to do a recursive call to __get
which will be denied.
I don’t know if it’s a bug or a feature. Read this page from the PHP manual and search for ‘recursi’ for further reading.
0
solved PHP __get magic method unexpected behaviour