diff --git a/Zend/tests/closure_001.phpt b/Zend/tests/closure/001.phpt similarity index 100% rename from Zend/tests/closure_001.phpt rename to Zend/tests/closure/001.phpt diff --git a/Zend/tests/closure_002.phpt b/Zend/tests/closure/002.phpt similarity index 100% rename from Zend/tests/closure_002.phpt rename to Zend/tests/closure/002.phpt diff --git a/Zend/tests/closure_003.phpt b/Zend/tests/closure/003.phpt similarity index 100% rename from Zend/tests/closure_003.phpt rename to Zend/tests/closure/003.phpt diff --git a/Zend/tests/closure_004.phpt b/Zend/tests/closure/004.phpt similarity index 100% rename from Zend/tests/closure_004.phpt rename to Zend/tests/closure/004.phpt diff --git a/Zend/tests/closure_005.phpt b/Zend/tests/closure/005.phpt similarity index 90% rename from Zend/tests/closure_005.phpt rename to Zend/tests/closure/005.phpt index 4e32faa017d75..97e31a6a36f73 100644 --- a/Zend/tests/closure_005.phpt +++ b/Zend/tests/closure/005.phpt @@ -71,4 +71,4 @@ echo "Done\n"; 7 Destroyed -Fatal error: Using $this when not in object context in %sclosure_005.php on line 28 +Fatal error: Using $this when not in object context in %s on line 28 diff --git a/Zend/tests/closure_006.phpt b/Zend/tests/closure/006.phpt similarity index 100% rename from Zend/tests/closure_006.phpt rename to Zend/tests/closure/006.phpt diff --git a/Zend/tests/closure_007.phpt b/Zend/tests/closure/007.phpt similarity index 100% rename from Zend/tests/closure_007.phpt rename to Zend/tests/closure/007.phpt diff --git a/Zend/tests/closure_008.phpt b/Zend/tests/closure/008.phpt similarity index 100% rename from Zend/tests/closure_008.phpt rename to Zend/tests/closure/008.phpt diff --git a/Zend/tests/closure_009.phpt b/Zend/tests/closure/009.phpt similarity index 100% rename from Zend/tests/closure_009.phpt rename to Zend/tests/closure/009.phpt diff --git a/Zend/tests/closure_010.phpt b/Zend/tests/closure/010.phpt similarity index 100% rename from Zend/tests/closure_010.phpt rename to Zend/tests/closure/010.phpt diff --git a/Zend/tests/closure_011.phpt b/Zend/tests/closure/011.phpt similarity index 100% rename from Zend/tests/closure_011.phpt rename to Zend/tests/closure/011.phpt diff --git a/Zend/tests/closure_012.phpt b/Zend/tests/closure/012.phpt similarity index 69% rename from Zend/tests/closure_012.phpt rename to Zend/tests/closure/012.phpt index 7e1b7a27937db..cbdc1454a06d2 100644 --- a/Zend/tests/closure_012.phpt +++ b/Zend/tests/closure/012.phpt @@ -16,9 +16,9 @@ $lambda(); var_dump($i); ?> --EXPECTF-- -Notice: Undefined variable: i in %sclosure_012.php on line 2 +Notice: Undefined variable: i in %s on line 2 -Notice: Undefined variable: i in %sclosure_012.php on line 7 +Notice: Undefined variable: i in %s on line 7 NULL int(2) diff --git a/Zend/tests/closure_013.phpt b/Zend/tests/closure/013.phpt similarity index 100% rename from Zend/tests/closure_013.phpt rename to Zend/tests/closure/013.phpt diff --git a/Zend/tests/closure_014.phpt b/Zend/tests/closure/014.phpt similarity index 100% rename from Zend/tests/closure_014.phpt rename to Zend/tests/closure/014.phpt diff --git a/Zend/tests/closure_015.phpt b/Zend/tests/closure/015.phpt similarity index 90% rename from Zend/tests/closure_015.phpt rename to Zend/tests/closure/015.phpt index 33c732d723722..a5687418bab66 100644 --- a/Zend/tests/closure_015.phpt +++ b/Zend/tests/closure/015.phpt @@ -14,6 +14,6 @@ print $x; print "\n"; ?> --EXPECTF-- -Error: Object of class Closure could not be converted to string at %sclosure_015.php(8) +Error: Object of class Closure could not be converted to string at %s(8) -Error: Object of class Closure could not be converted to string at %sclosure_015.php(10) +Error: Object of class Closure could not be converted to string at %s(10) diff --git a/Zend/tests/closure_016.phpt b/Zend/tests/closure/016.phpt similarity index 100% rename from Zend/tests/closure_016.phpt rename to Zend/tests/closure/016.phpt diff --git a/Zend/tests/closure_017.phpt b/Zend/tests/closure/017.phpt similarity index 100% rename from Zend/tests/closure_017.phpt rename to Zend/tests/closure/017.phpt diff --git a/Zend/tests/closure_018.phpt b/Zend/tests/closure/018.phpt similarity index 89% rename from Zend/tests/closure_018.phpt rename to Zend/tests/closure/018.phpt index 2dcf15c6aa161..4b5e37050a39d 100644 --- a/Zend/tests/closure_018.phpt +++ b/Zend/tests/closure/018.phpt @@ -22,10 +22,10 @@ var_dump($y, $x); ?> --EXPECTF-- -Notice: Only variable references should be returned by reference in %sclosure_018.php on line 7 +Notice: Only variable references should be returned by reference in %s on line 7 int(4) -Notice: Only variable references should be returned by reference in %sclosure_018.php on line 7 +Notice: Only variable references should be returned by reference in %s on line 7 int(16) int(16) int(16) diff --git a/Zend/tests/closure_019.phpt b/Zend/tests/closure/019.phpt similarity index 88% rename from Zend/tests/closure_019.phpt rename to Zend/tests/closure/019.phpt index 57aa2dec17cf7..aef16e89a39ea 100644 --- a/Zend/tests/closure_019.phpt +++ b/Zend/tests/closure/019.phpt @@ -20,10 +20,10 @@ test(); ?> --EXPECTF-- -Notice: Only variable references should be returned by reference in %sclosure_019.php on line 4 +Notice: Only variable references should be returned by reference in %s on line 4 int(9) -Notice: Only variable references should be returned by reference in %sclosure_019.php on line 4 +Notice: Only variable references should be returned by reference in %s on line 4 int(81) -Fatal error: Cannot pass parameter 1 by reference in %s on line %d +Fatal error: Cannot pass parameter 1 by reference in %s on line %d diff --git a/Zend/tests/closure_020.phpt b/Zend/tests/closure/020.phpt similarity index 100% rename from Zend/tests/closure_020.phpt rename to Zend/tests/closure/020.phpt diff --git a/Zend/tests/closure_021.phpt b/Zend/tests/closure/021.phpt similarity index 100% rename from Zend/tests/closure_021.phpt rename to Zend/tests/closure/021.phpt diff --git a/Zend/tests/closure_022.phpt b/Zend/tests/closure/022.phpt similarity index 87% rename from Zend/tests/closure_022.phpt rename to Zend/tests/closure/022.phpt index 8621d2c095f9c..c2d45c3af288a 100644 --- a/Zend/tests/closure_022.phpt +++ b/Zend/tests/closure/022.phpt @@ -8,5 +8,5 @@ $foo = function() use ($a) { $foo->a = 1; ?> --EXPECTF-- -Catchable fatal error: Closure object cannot have properties in %sclosure_022.php on line 5 +Catchable fatal error: Closure object cannot have properties in %s22.php on line 5 diff --git a/Zend/tests/closure_023.phpt b/Zend/tests/closure/023.phpt similarity index 100% rename from Zend/tests/closure_023.phpt rename to Zend/tests/closure/023.phpt diff --git a/Zend/tests/closure_024.phpt b/Zend/tests/closure/024.phpt similarity index 100% rename from Zend/tests/closure_024.phpt rename to Zend/tests/closure/024.phpt diff --git a/Zend/tests/closure_025.phpt b/Zend/tests/closure/025.phpt similarity index 100% rename from Zend/tests/closure_025.phpt rename to Zend/tests/closure/025.phpt diff --git a/Zend/tests/closure_026.phpt b/Zend/tests/closure/026.phpt similarity index 100% rename from Zend/tests/closure_026.phpt rename to Zend/tests/closure/026.phpt diff --git a/Zend/tests/closure_027.phpt b/Zend/tests/closure/027.phpt similarity index 100% rename from Zend/tests/closure_027.phpt rename to Zend/tests/closure/027.phpt diff --git a/Zend/tests/closure_028.phpt b/Zend/tests/closure/028.phpt similarity index 100% rename from Zend/tests/closure_028.phpt rename to Zend/tests/closure/028.phpt diff --git a/Zend/tests/closure_029.phpt b/Zend/tests/closure/029.phpt similarity index 100% rename from Zend/tests/closure_029.phpt rename to Zend/tests/closure/029.phpt diff --git a/Zend/tests/closure_030.phpt b/Zend/tests/closure/030.phpt similarity index 100% rename from Zend/tests/closure_030.phpt rename to Zend/tests/closure/030.phpt diff --git a/Zend/tests/closure_031.phpt b/Zend/tests/closure/031.phpt similarity index 100% rename from Zend/tests/closure_031.phpt rename to Zend/tests/closure/031.phpt diff --git a/Zend/tests/closure_032.phpt b/Zend/tests/closure/032.phpt similarity index 100% rename from Zend/tests/closure_032.phpt rename to Zend/tests/closure/032.phpt diff --git a/Zend/tests/closure_033.phpt b/Zend/tests/closure/033.phpt similarity index 92% rename from Zend/tests/closure_033.phpt rename to Zend/tests/closure/033.phpt index f6510066bbc68..ad9eee8fa5b61 100644 --- a/Zend/tests/closure_033.phpt +++ b/Zend/tests/closure/033.phpt @@ -25,4 +25,4 @@ $o->func(); --EXPECTF-- Test::{closure}() -Fatal error: Call to private method Test::func() from context '' in %sclosure_033.php on line %d +Fatal error: Call to private method Test::func() from context '' in %s on line %d diff --git a/Zend/tests/closure_034.phpt b/Zend/tests/closure/034.phpt similarity index 100% rename from Zend/tests/closure_034.phpt rename to Zend/tests/closure/034.phpt diff --git a/Zend/tests/closure_035.phpt b/Zend/tests/closure/035.phpt similarity index 100% rename from Zend/tests/closure_035.phpt rename to Zend/tests/closure/035.phpt diff --git a/Zend/tests/closure_036.phpt b/Zend/tests/closure/036.phpt similarity index 100% rename from Zend/tests/closure_036.phpt rename to Zend/tests/closure/036.phpt diff --git a/Zend/tests/closure_037.phpt b/Zend/tests/closure/037.phpt similarity index 100% rename from Zend/tests/closure_037.phpt rename to Zend/tests/closure/037.phpt diff --git a/Zend/tests/closure_038.phpt b/Zend/tests/closure/038.phpt similarity index 100% rename from Zend/tests/closure_038.phpt rename to Zend/tests/closure/038.phpt diff --git a/Zend/tests/closure_039.phpt b/Zend/tests/closure/039.phpt similarity index 100% rename from Zend/tests/closure_039.phpt rename to Zend/tests/closure/039.phpt diff --git a/Zend/tests/closure_040.phpt b/Zend/tests/closure/040.phpt similarity index 100% rename from Zend/tests/closure_040.phpt rename to Zend/tests/closure/040.phpt diff --git a/Zend/tests/closure_041.phpt b/Zend/tests/closure/041.phpt similarity index 100% rename from Zend/tests/closure_041.phpt rename to Zend/tests/closure/041.phpt diff --git a/Zend/tests/closure_042.phpt b/Zend/tests/closure/042.phpt similarity index 100% rename from Zend/tests/closure_042.phpt rename to Zend/tests/closure/042.phpt diff --git a/Zend/tests/closure_043.phpt b/Zend/tests/closure/043.phpt similarity index 100% rename from Zend/tests/closure_043.phpt rename to Zend/tests/closure/043.phpt diff --git a/Zend/tests/closure_044.phpt b/Zend/tests/closure/044.phpt similarity index 100% rename from Zend/tests/closure_044.phpt rename to Zend/tests/closure/044.phpt diff --git a/Zend/tests/closure_045.phpt b/Zend/tests/closure/045.phpt similarity index 100% rename from Zend/tests/closure_045.phpt rename to Zend/tests/closure/045.phpt diff --git a/Zend/tests/closure_046.phpt b/Zend/tests/closure/046.phpt similarity index 100% rename from Zend/tests/closure_046.phpt rename to Zend/tests/closure/046.phpt diff --git a/Zend/tests/closure_047.phpt b/Zend/tests/closure/047.phpt similarity index 100% rename from Zend/tests/closure_047.phpt rename to Zend/tests/closure/047.phpt diff --git a/Zend/tests/closure_048.phpt b/Zend/tests/closure/048.phpt similarity index 100% rename from Zend/tests/closure_048.phpt rename to Zend/tests/closure/048.phpt diff --git a/Zend/tests/closure/049.phpt b/Zend/tests/closure/049.phpt new file mode 100644 index 0000000000000..e812c9fe729a7 --- /dev/null +++ b/Zend/tests/closure/049.phpt @@ -0,0 +1,21 @@ +--TEST-- +Closure 049: static::class in static closure in non-static method. + +--FILE-- +foo()); +--EXPECT-- +string(1) "B" diff --git a/Zend/tests/closure/050.phpt b/Zend/tests/closure/050.phpt new file mode 100644 index 0000000000000..d43f325ef1f67 --- /dev/null +++ b/Zend/tests/closure/050.phpt @@ -0,0 +1,22 @@ +--TEST-- +Closure 050: static::class in non-static closure in non-static method. + +--FILE-- +foo()); + +--EXPECT-- +string(1) "B" diff --git a/Zend/tests/closure/051.phpt b/Zend/tests/closure/051.phpt new file mode 100644 index 0000000000000..78b28d74a33d7 --- /dev/null +++ b/Zend/tests/closure/051.phpt @@ -0,0 +1,21 @@ +--TEST-- +Closure 051: static::class in static closure in static method. + +--FILE-- +foo()); + +--EXPECT-- +string(1) "A" diff --git a/Zend/tests/closure/054.phpt b/Zend/tests/closure/054.phpt new file mode 100644 index 0000000000000..b2f87d1d6109f --- /dev/null +++ b/Zend/tests/closure/054.phpt @@ -0,0 +1,22 @@ +--TEST-- +Closure 054: self::class in non-static closure in non-static method. + +--FILE-- +foo()); + +--EXPECT-- +string(1) "A" diff --git a/Zend/tests/closure/055.phpt b/Zend/tests/closure/055.phpt new file mode 100644 index 0000000000000..047d72a89bd61 --- /dev/null +++ b/Zend/tests/closure/055.phpt @@ -0,0 +1,21 @@ +--TEST-- +Closure 055: self::class in static closure in static method. + +--FILE-- +foo(); + (new B)->bar(); + (new B)->baz(); + B::baz(); +} +test(); + +--EXPECT-- +B vs B +B vs B +B vs B +B vs B diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index d714b35b399e1..bd2ede329d7fa 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -480,6 +480,7 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_ent } } + closure->this_ptr = NULL; /* Invariants: * If the closure is unscoped, it has no bound object. * The the closure is scoped, it's either static or it's bound */ @@ -491,10 +492,7 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_ent Z_ADDREF_P(this_ptr); } else { closure->func.common.fn_flags |= ZEND_ACC_STATIC; - closure->this_ptr = NULL; } - } else { - closure->this_ptr = NULL; } } /* }}} */ diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 195772a3954c1..0ab4b9462a5f3 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5408,7 +5408,13 @@ ZEND_VM_HANDLER(153, ZEND_DECLARE_LAMBDA_FUNCTION, CONST, UNUSED) zend_error_noreturn(E_ERROR, "Base lambda function for closure not found"); } - zend_create_closure(&EX_T(opline->result.var).tmp_var, (zend_function *) op_array, EG(scope), EG(This) TSRMLS_CC); + int defined_function_is_static = op_array->common.fn_flags & ZEND_ACC_STATIC; + int function_is_being_defined_inside_static_context = EX(prev_execute_data) && EX(prev_execute_data)->function_state.function->common.fn_flags & ZEND_ACC_STATIC; + if (defined_function_is_static || function_is_being_defined_inside_static_context) { + zend_create_closure(&EX_T(opline->result.var).tmp_var, (zend_function *) op_array, EG(called_scope), NULL TSRMLS_CC); + } else { + zend_create_closure(&EX_T(opline->result.var).tmp_var, (zend_function *) op_array, EG(scope), EG(This) TSRMLS_CC); + } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 4690c3e3ae117..cf38c7dab6f2d 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -6789,7 +6789,13 @@ static int ZEND_FASTCALL ZEND_DECLARE_LAMBDA_FUNCTION_SPEC_CONST_UNUSED_HANDLER zend_error_noreturn(E_ERROR, "Base lambda function for closure not found"); } - zend_create_closure(&EX_T(opline->result.var).tmp_var, (zend_function *) op_array, EG(scope), EG(This) TSRMLS_CC); + int defined_function_is_static = op_array->common.fn_flags & ZEND_ACC_STATIC; + int function_is_being_defined_inside_static_context = EX(prev_execute_data) && EX(prev_execute_data)->function_state.function->common.fn_flags & ZEND_ACC_STATIC; + if (defined_function_is_static || function_is_being_defined_inside_static_context) { + zend_create_closure(&EX_T(opline->result.var).tmp_var, (zend_function *) op_array, EG(called_scope), NULL TSRMLS_CC); + } else { + zend_create_closure(&EX_T(opline->result.var).tmp_var, (zend_function *) op_array, EG(scope), EG(This) TSRMLS_CC); + } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE();