Skip to content

Commit e81419d

Browse files
committed
Core: convert bail-out for incorect __debugInfo return type to TypeError
1 parent d2a932b commit e81419d

14 files changed

+107
-253
lines changed

Zend/tests/debug_info-error-0.0.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-0.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-1.0.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-1.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-empty_str.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-false.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-object.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-resource.phpt

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$VALUES = [
17+
false,
18+
true,
19+
0,
20+
0.0,
21+
1.0,
22+
1,
23+
"",
24+
"foo",
25+
new stdClass(),
26+
STDERR,
27+
];
28+
29+
foreach ($VALUES as $value) {
30+
$c = new C($value);
31+
32+
try {
33+
var_dump($c);
34+
} catch (Throwable $e) {
35+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
36+
}
37+
}
38+
?>
39+
--EXPECT--
40+
TypeError: __debuginfo() must return an array
41+
TypeError: __debuginfo() must return an array
42+
TypeError: __debuginfo() must return an array
43+
TypeError: __debuginfo() must return an array
44+
TypeError: __debuginfo() must return an array
45+
TypeError: __debuginfo() must return an array
46+
TypeError: __debuginfo() must return an array
47+
TypeError: __debuginfo() must return an array
48+
TypeError: __debuginfo() must return an array
49+
TypeError: __debuginfo() must return an array

Zend/tests/debug_info-error-str.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/tests/debug_info-error-true.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

Zend/zend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /*
573573
}
574574

575575
if ((properties = zend_get_properties_for(expr, ZEND_PROP_PURPOSE_DEBUG)) == NULL) {
576-
print_hash(buf, (HashTable*) &zend_empty_array, indent, 1);
577-
break;
576+
/* An exception has been thrown */
577+
return;
578578
}
579579

580580
ZEND_GUARD_OR_GC_PROTECT_RECURSION(guard, DEBUG, zobj);

Zend/zend_object_handlers.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /
159159
HashTable *ht;
160160

161161
if (!ce->__debugInfo) {
162-
*is_temp = 0;
162+
*is_temp = false;
163163
return object->handlers->get_properties(object);
164164
}
165165

@@ -178,14 +178,14 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /
178178
return Z_ARRVAL(retval);
179179
}
180180
} else if (Z_TYPE(retval) == IS_NULL) {
181-
*is_temp = 1;
182-
ht = zend_new_array(0);
183-
return ht;
181+
*is_temp = 0;
182+
zval_ptr_dtor(&retval);
183+
return (HashTable*)&zend_empty_array;
184+
} else {
185+
zval_ptr_dtor(&retval);
186+
zend_type_error(ZEND_DEBUGINFO_FUNC_NAME "() must return an array");
187+
return NULL;
184188
}
185-
186-
zend_error_noreturn(E_ERROR, ZEND_DEBUGINFO_FUNC_NAME "() must return an array");
187-
188-
return NULL; /* Compilers are dumb and don't understand that noreturn means that the function does NOT need a return value... */
189189
}
190190
/* }}} */
191191

0 commit comments

Comments
 (0)