Skip to content

Commit 7e597f4

Browse files
committed
Fixed bug #77339 (__callStatic may get incorrect arguments)
1 parent 64de5bc commit 7e597f4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PHP NEWS
1010
(Valentin V. Bartenev)
1111
. Fixed bug #76046 (PHP generates "FE_FREE" opcode on the wrong line).
1212
(Nikita)
13+
. Fixed bug #77339 (__callStatic may get incorrect arguments). (Dmitry)
1314

1415
- COM:
1516
. Fixed bug #77177 (Serializing or unserializing COM objects crashes). (cmb)

Zend/tests/bug77339.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #77339 (__callStatic may get incorrect arguments)
3+
--FILE--
4+
<?php
5+
class Foo
6+
{
7+
static function __callStatic($name, $arguments) {
8+
if ($name === 'get') {
9+
if (!isset($arguments[0])) {
10+
var_dump(['getSomeWhat']);
11+
var_dump($arguments);
12+
exit;
13+
}
14+
}
15+
echo "OK\n";
16+
}
17+
18+
protected function get ($key) {
19+
echo "BUG!!!\n";
20+
}
21+
}
22+
23+
class Bar
24+
{
25+
static function __callStatic($name, $arguments) {
26+
echo Foo::get('getSomeWhat');
27+
}
28+
}
29+
30+
Bar::someUndefinedStaticFunction();
31+
?>
32+
--EXPECT--
33+
OK

Zend/zend_compile.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,14 @@ void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type) /* {{
41274127
if (ce) {
41284128
zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op2) + 1);
41294129
fbc = zend_hash_find_ptr(&ce->function_table, lcname);
4130+
if (fbc && !(fbc->common.fn_flags & ZEND_ACC_PUBLIC)) {
4131+
if (ce != CG(active_class_entry)
4132+
&&((fbc->common.fn_flags & ZEND_ACC_PRIVATE)
4133+
|| !zend_check_protected(zend_get_function_root_class(fbc), CG(active_class_entry)))) {
4134+
/* incompatibe function */
4135+
fbc = NULL;
4136+
}
4137+
}
41304138
}
41314139
}
41324140

0 commit comments

Comments
 (0)