File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Behavior of static variable in private trait method
3
+ --FILE--
4
+ <?php
5
+
6
+ trait T {
7
+ private static function method () {
8
+ static $ x ;
9
+ if ($ x === null ) $ x = new stdClass ;
10
+ return $ x ;
11
+ }
12
+
13
+ public static function method2 () {
14
+ return self ::method ();
15
+ }
16
+ }
17
+
18
+ class C {
19
+ use T;
20
+ }
21
+
22
+ var_dump (C::method2 ());
23
+
24
+ class D extends C {
25
+ use T;
26
+ }
27
+
28
+ var_dump (D::method2 ());
29
+
30
+ ?>
31
+ --EXPECT--
32
+ object(stdClass)#1 (0) {
33
+ }
34
+ object(stdClass)#2 (0) {
35
+ }
Original file line number Diff line number Diff line change @@ -95,11 +95,19 @@ static zend_always_inline zend_function *zend_duplicate_function(zend_function *
95
95
(* func -> op_array .refcount )++ ;
96
96
}
97
97
if (is_interface
98
- || EXPECTED (!func -> op_array .static_variables )
99
- || (func -> op_array .fn_flags & ZEND_ACC_PRIVATE )) {
98
+ || EXPECTED (!func -> op_array .static_variables )) {
100
99
/* reuse the same op_array structure */
101
100
return func ;
102
101
}
102
+ if (func -> op_array .fn_flags & ZEND_ACC_PRIVATE ) {
103
+ /* For private methods we reuse the same op_array structure even if
104
+ * static variables are used, because it will not end up being used
105
+ * anyway. However we still need to addref as the dtor will delref. */
106
+ if (!(GC_FLAGS (func -> op_array .static_variables ) & IS_ARRAY_IMMUTABLE )) {
107
+ GC_ADDREF (func -> op_array .static_variables );
108
+ }
109
+ return func ;
110
+ }
103
111
return zend_duplicate_user_function (func );
104
112
}
105
113
}
Original file line number Diff line number Diff line change @@ -167,8 +167,9 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
167
167
* doesn't work.
168
168
*/
169
169
#if defined(__i386__ ) || defined(__x86_64__ ) || defined(__vax__ )
170
+ typedef ZEND_SET_ALIGNED (1 , uint32_t unaligned_uint32_t ) ;
170
171
# define SET (n ) \
171
- (*(uint32_t *)&ptr[(n) * 4])
172
+ (*(unaligned_uint32_t *)&ptr[(n) * 4])
172
173
# define GET (n ) \
173
174
SET(n)
174
175
#else
You can’t perform that action at this time.
0 commit comments