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

- Thread: https://externals.io/message/7473
- Original archive: https://news-web.php.net/php.internals/7473
- Started by Stephane Drouard on 2004-02-02T15:33:45+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #7473 — Stephane Drouard — 2004-02-02T15:33:45+00:00

URL: https://externals.io/message/7473#7473

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

---

## #7474 — Christian Schneider — 2004-02-02T15:43:00+00:00

URL: https://externals.io/message/7473#7474 · In reply to: #7473

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

---

## #7549 — Stephane Drouard — 2004-02-04T17:29:14+00:00

URL: https://externals.io/message/7473#7549 · In reply to: #7473

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

---

## #7690 — Zeev Suraski — 2004-02-10T10:19:43+00:00

URL: https://externals.io/message/7473#7690 · In reply to: #7473

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
