Skip to content

Commit

Permalink
Fixed bug xdebug#723: xdebug is stricter than PHP regarding Exception…
Browse files Browse the repository at this point in the history
… property types.
  • Loading branch information
derickr committed Sep 30, 2011
1 parent 6b60864 commit b0faa73
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
12 changes: 10 additions & 2 deletions tests/bug00340.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyException extends Exception
{
function __construct()
{
$this->message = new StdClass;
$this->message = array(1, 2, 3);
}
}

Expand All @@ -22,7 +22,15 @@ throw new MyException();
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Your exception class uses incorrect types for common properties: 'message' and 'file' need to be a string and 'line' needs to be an integer. in %sbug00340.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Array to string conversion in %sbug00340.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>{main}( )</td><td title='%sbug00340.php' bgcolor='#eeeeec'>../bug00340.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught exception 'MyException' with message 'Array' in %sbug00340.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> MyException: Array in %sbug00340.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>{main}( )</td><td title='%sbug00340.php' bgcolor='#eeeeec'>../bug00340.php<b>:</b>0</td></tr>
Expand Down
24 changes: 24 additions & 0 deletions tests/bug00723.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Test for bug #723: xdebug is stricter than PHP regarding Exception property types
--INI--
html_errors=0
display_errors=1
error_reporting=-1
--FILE--
<?php
class MyException extends Exception {
function __construct($message) {
parent::__construct($message);
$this->line = "42"; // this triggers it. if it's before the constructor, PHP freaks out regardless of xdebug
}
}

try {
throw new MyException('test');
} catch (Exception $ex) {
}

echo "survived";
?>
--EXPECTF--
survived
6 changes: 3 additions & 3 deletions xdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,9 @@ static void xdebug_throw_exception_hook(zval *exception TSRMLS_DC)
file = zend_read_property(default_ce, exception, "file", sizeof("file")-1, 0 TSRMLS_CC);
line = zend_read_property(default_ce, exception, "line", sizeof("line")-1, 0 TSRMLS_CC);

if (Z_TYPE_P(message) != IS_STRING || Z_TYPE_P(file) != IS_STRING || Z_TYPE_P(line) != IS_LONG) {
php_error(E_ERROR, "Your exception class uses incorrect types for common properties: 'message' and 'file' need to be a string and 'line' needs to be an integer.");
}
convert_to_string_ex(&message);
convert_to_string_ex(&file);
convert_to_long_ex(&line);

#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6
previous_exception = zend_read_property(default_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC);
Expand Down

0 comments on commit b0faa73

Please sign in to comment.