When trying to derive from class Exception and access the 'string'
property or call 'parent::__toString' PHP segfaults:
<?php
class MyException extends Exception {
function __toString() {
var_dump($this->string);
}
}
throw new MyException("hmm");
?>
Output:
$ php testException.php
NULL
Segmentation fault
Or this example:
<?php
class MyException extends Exception {
function __toString() {
parent::__toString();
}
}
throw new MyException("hmm");
?>
Output:
$ php testException.php
Segmentation fault
The need for this came up when I saw that the reported exception is
not foramted in the HTML output; it's quite hard next to impossible
to properly read the stack trace. So my goal was to make my own
exception and call `nl2br()` on the string returned from the class.
Besides the segfaults above, is there a chance we have a nicer HTML
formatting for reported Exceptions (while still strip those HTML
tags from it for logging)?
- Markus
Hello Markus,
this works now.
regards
marcus (the other one)
Saturday, November 29, 2003, 3:39:17 PM, you wrote:
When trying to derive from class Exception and access the 'string'
property or call 'parent::__toString' PHP segfaults:
<?php
class MyException extends Exception {
function __toString() {
var_dump($this->string);
}
}
throw new MyException("hmm");
?>>
Output:
$ php testException.php
NULL
Segmentation fault
Or this example:
<?php
class MyException extends Exception {
function __toString() {
parent::__toString();
}
}
throw new MyException("hmm");
?>>
Output:
$ php testException.php
Segmentation fault
The need for this came up when I saw that the reported exception is
not foramted in the HTML output; it's quite hard next to impossible
to properly read the stack trace. So my goal was to make my own
exception and callnl2br()
on the string returned from the class.
Besides the segfaults above, is there a chance we have a nicer HTML
formatting for reported Exceptions (while still strip those HTML
tags from it for logging)?
- Markus
--
Best regards,
Marcus mailto:helly@php.net
Hi Marcus,
On Sat, Nov 29, 2003 at 06:09:36PM +0100, Marcus Boerger wrote :
Hello Markus,
this works now.
regards
marcus (the other one)
Thanks, calling parent::__toString() or accessing $this->string
works now. I've found just another scenario which causes a segfault.
If you do not return anything from __toString() or return int or an
object, php segfaults:
<?php
class MyException extends Exception {
function __toString() {
# segfault
#return 1;
# segfault
#return new StdClass
# no segfault
#return array("foo");
# segfault (no return statement)
}
}
throw new MyException("hmm");
?>
Output:
$ php testException.php
Segmentation fault
- Markus
Hi,
On Sat, Nov 29, 2003 at 06:09:36PM +0100, Marcus Boerger wrote :
this works now.
Thanks. Sorry for the order of reply of the mails, my spam filer
catches this one and I only discovered it yet.
Besides the segfaults above, is there a chance we have a nicer HTML formatting for reported Exceptions (while still strip those HTML tags from it for logging)?
Can you advise in this issue too?
The thing is, the stack trace is alright and looks good, but not in
HTML since the line breaks are ordinary ones; there's not HTML
formatting for them, so the line break is not visible in the HTML
output.
If I derive my own exception and override __toString() I can call
`nl2br()`; but then I've the HTML output in the error_log too.
Seems like an chicken and egg problem. Another solution is to modify
error_prepend/append to encapuslate the error output in a pre block.
Besides this possible, would it be feasable to handle this issue
right away in PHP for HTML and error log output? Maybe it's not
possible anyway. Hm.
- Markus
Hello Markus,
Sunday, November 30, 2003, 10:59:50 PM, you wrote:
Hi,
On Sat, Nov 29, 2003 at 06:09:36PM +0100, Marcus Boerger wrote :
this works now.
Thanks. Sorry for the order of reply of the mails, my spam filer catches this one and I only discovered it yet.
Besides the segfaults above, is there a chance we have a nicer HTML
formatting for reported Exceptions (while still strip those HTML
tags from it for logging)?
Can you advise in this issue too?
The thing is, the stack trace is alright and looks good, but not in HTML since the line breaks are ordinary ones; there's not HTML formatting for them, so the line break is not visible in the HTML output.
If I derive my own exception and override __toString() I can call `nl2br()`; but then I've the HTML output in the error_log too.
Seems like an chicken and egg problem. Another solution is to modify error_prepend/append to encapuslate the error output in a pre block.
There you go.
Besides this possible, would it be feasable to handle this issue right away in PHP for HTML and error log output? Maybe it's not possible anyway. Hm.
I don't think this makes sense but maybe we could try to establish a
callback into main to display uncaught exceptions. But this must wait until
after 5 release i think.
--
Best regards,
Marcus mailto:helly@php.net