Skip to content

Commit b6bee2c

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix missing addref for Countable::count()
2 parents 159725d + 55c2dbb commit b6bee2c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Zend/tests/gh21605.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-21605: Missing addref for Countable::count()
3+
--CREDITS--
4+
cnwangjihe
5+
--FILE--
6+
<?php
7+
8+
class C implements Countable {
9+
public function count(): int {
10+
global $c;
11+
$c = null;
12+
var_dump($this);
13+
return 42;
14+
}
15+
}
16+
17+
$c = new C;
18+
var_dump(count($c));
19+
20+
?>
21+
--EXPECTF--
22+
object(C)#%d (0) {
23+
}
24+
int(42)

Zend/zend_vm_def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9580,7 +9580,9 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMP|CV, UNUSED)
95809580
zval retval;
95819581

95829582
zend_function *count_fn = zend_hash_find_ptr(&zobj->ce->function_table, ZSTR_KNOWN(ZEND_STR_COUNT));
9583+
GC_ADDREF(zobj);
95839584
zend_call_known_instance_method_with_0_params(count_fn, zobj, &retval);
9585+
OBJ_RELEASE(zobj);
95849586
count = zval_get_long(&retval);
95859587
zval_ptr_dtor(&retval);
95869588
break;

Zend/zend_vm_execute.h

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

0 commit comments

Comments
 (0)