Skip to content

Commit e9283c0

Browse files
committed
Fix phpGH-16574: Incorrect error "undefined method" messages
The `get_method` object handler may change the object pointer. SPL does this in its iterator implementations. This causes the error message to change to another class which is confusing to the user. JIT handles this correctly. This patch aligns behaviour with JIT. Closes phpGH-16576.
1 parent 9ee204f commit e9283c0

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.0RC4
44

5+
- Core:
6+
. Fixed bug GH-16574 (Incorrect error "undefined method" messages).
7+
(nielsdos)
8+
59
- GD:
610
. Fixed bug GH-16559 (UBSan abort in ext/gd/libgd/gd_interpolation.c:1007).
711
(nielsdos)

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3625,7 +3625,7 @@ ZEND_VM_HOT_OBJ_HANDLER(112, ZEND_INIT_METHOD_CALL, CONST|TMPVAR|UNUSED|THIS|CV,
36253625
fbc = obj->handlers->get_method(&obj, Z_STR_P(function_name), ((OP2_TYPE == IS_CONST) ? (RT_CONSTANT(opline, opline->op2) + 1) : NULL));
36263626
if (UNEXPECTED(fbc == NULL)) {
36273627
if (EXPECTED(!EG(exception))) {
3628-
zend_undefined_method(obj->ce, Z_STR_P(function_name));
3628+
zend_undefined_method(orig_obj->ce, Z_STR_P(function_name));
36293629
}
36303630
FREE_OP2();
36313631
if ((OP1_TYPE & (IS_VAR|IS_TMP_VAR)) && GC_DELREF(orig_obj) == 0) {

Zend/zend_vm_execute.h

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/spl/tests/gh16574.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-16574 (Incorrect error "undefined method" messages)
3+
--CREDITS--
4+
YuanchengJiang
5+
--FILE--
6+
<?php
7+
$i = new ArrayIterator([1,1,1,1,1]);
8+
$i = new CachingIterator($i, CachingIterator::FULL_CACHE);
9+
$i->doesnotexist("x");
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught Error: Call to undefined method CachingIterator::doesnotexist() in %s:%d
13+
Stack trace:
14+
#0 {main}
15+
thrown in %s on line %d

0 commit comments

Comments
 (0)