FAQ
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

Search Discussions

  • Christian Schneider at Feb 2, 2004 at 3:43 pm

    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 at Feb 4, 2004 at 5:29 pm
    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 at Feb 10, 2004 at 10:19 am

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedFeb 2, '04 at 3:33p
activeFeb 10, '04 at 10:19a
posts4
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase