PHP5: Exception not correctly thown with __get, __set and __toString

php.internals

Stephane Drouard

22 years ago
Hello, The following code does not work as expected: <? class Test { function __get($n) { print('[get]'); throw new Exception('get'); print('[/get]'); // not printed: OK } } print('[test]'); $o = new Test(); $v = $o->foo; print('[/test]'); // printed: bug ?> '/get' is not printed, so the throw statement is correctly executed, but '/test' is printed, so the exception is not correctly "propagated" to the caller. Note that the exception will be thrown later, either: * if the call to __get was not in a function: end of script, * if the call to __get was within a function: end of the function, except if antoher exception is thrown, but in that case the get exception is reported, not the newly thrown one. Same behaviour with __set and __toString. Apparently no problems with __construct, __destruct, __call and __clone. Regards, Stephane

Christian Schneider

22 years ago
Stephane Drouard wrote:
> The following code does not work as expected:
I think it is a very good thing to test these things and I think it should be turned into phpt tests and added to the distribution. - Chris

Stephane Drouard

22 years ago
The new implementation of exception mechanism solves the problem with __get and __toString, but throwing an exception within __set results in a segmentation fault. Stephane

Zeev Suraski

22 years ago
At 19:29 04/02/2004, Stephane Drouard wrote:
>The new implementation of exception mechanism solves the problem with >__get and __toString, but throwing an exception within __set results in a >segmentation fault.
Fixed! Zeev