Skip to content

Commit 34c460f

Browse files
committed
Check __set_state structure
Fix Bug #79521. Closes GH-5462.
1 parent f545ee2 commit 34c460f

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PHP NEWS
2323
. Fixed bug #36365 (scandir duplicates file name at every 65535th file).
2424
(cmb)
2525
. Use SSE2 instructions do locale independent strtolower. (Laruence)
26+
. Fixed bug #79521 (Check __set_state structure). (carusogabriel)
2627

2728
- BZ2:
2829
. Fixed bug #71263 (fread() does not report bzip2.decompress errors). (cmb)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Testing __set_state() declaration with wrong modifier
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
function __set_state()
8+
{
9+
}
10+
}
11+
12+
?>
13+
--EXPECTF--
14+
Warning: The magic method Foo::__set_state() must be static in %s on line %d

Zend/zend_compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6170,6 +6170,8 @@ zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name,
61706170
zend_check_magic_method_attr(fn_flags, ce, "__serialize", 0);
61716171
} else if (zend_string_equals_literal(lcname, "__unserialize")) {
61726172
zend_check_magic_method_attr(fn_flags, ce, "__unserialize", 0);
6173+
} else if (zend_string_equals_literal(lcname, "__set_state")) {
6174+
zend_check_magic_method_attr(fn_flags, ce, "__set_state", 1);
61736175
}
61746176

61756177
return lcname;

ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TestClass
5252

5353
public function __wakeup() {}
5454

55-
public function __set_state() {}
55+
public static function __set_state() {}
5656

5757
public function __autoload() {}
5858
}
@@ -143,7 +143,7 @@ Modifiers for method TestClass::__wakeup():
143143

144144

145145
Modifiers for method TestClass::__set_state():
146-
0x00000001
146+
0x00000011
147147

148148

149149
Modifiers for method TestClass::__autoload():
@@ -207,7 +207,7 @@ Modifiers for method TestClass::__wakeup():
207207

208208

209209
Modifiers for method TestClass::__set_state():
210-
0x00000001
210+
0x00000011
211211

212212

213213
Modifiers for method TestClass::__autoload():

0 commit comments

Comments
 (0)