This also adds some smaller, isolated tests related to bug 66622.
Conflicts:
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
. Fixed BC break introduced by patch for bug #67072. (Anatol)
. Fixed bug #67390 (insecure temporary file use in the configure script).
(Remi) (CVE-2014-3981)
+ . Fixed bug #66622 (Closures do not correctly capture the late bound class
+ (static::) in some cases). (Levi Morrison)
- Date:
. Fixed bug #67308 (Serialize of DateTime truncates fractions of second).
--- /dev/null
+--TEST--
+Bug 66622: Closures do not correctly capture the late bound class (static::) in some cases
+
+--FILE--
+<?php
+class A {
+ static function name() { return 'A'; }
+ function foo() {
+ $fn = function() { return static::name(); };
+ echo static::name() . ' vs ' . $fn() . "\n";
+ }
+ function bar() {
+ $fn = static function() { return static::name(); };
+ echo static::name() . ' vs ' . $fn() . "\n";
+ }
+ static function baz() {
+ $fn = function() { return static::name(); };
+ echo static::name() . ' vs ' . $fn() . "\n";
+ }
+}
+class B extends A {
+ static function name() { return 'B'; }
+}
+
+function test() {
+ (new B)->foo();
+ (new B)->bar();
+ (new B)->baz();
+ B::baz();
+}
+test();
+
+--EXPECT--
+B vs B
+B vs B
+B vs B
+B vs B
}
}
+ 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 */
Z_ADDREF_P(this_ptr);
} else {
closure->func.common.fn_flags |= ZEND_ACC_STATIC;
- closure->this_ptr = NULL;
}
- } else {
- closure->this_ptr = NULL;
}
}
/* }}} */
{
USE_OPLINE
zend_function *op_array;
+ int closure_is_static, closure_is_being_defined_inside_static_context;
SAVE_OPLINE();
zend_error_noreturn(E_ERROR, "Base lambda function for closure not found");
}
- zend_create_closure(&EX_T(opline->result.var).tmp_var, op_array, EG(scope), EG(This) TSRMLS_CC);
+ closure_is_static = op_array->common.fn_flags & ZEND_ACC_STATIC;
+ closure_is_being_defined_inside_static_context = EX(prev_execute_data) && EX(prev_execute_data)->function_state.function->common.fn_flags & ZEND_ACC_STATIC;
+ if (closure_is_static || closure_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();
{
USE_OPLINE
zend_function *op_array;
+ int closure_is_static, closure_is_being_defined_inside_static_context;
SAVE_OPLINE();
zend_error_noreturn(E_ERROR, "Base lambda function for closure not found");
}
- zend_create_closure(&EX_T(opline->result.var).tmp_var, op_array, EG(scope), EG(This) TSRMLS_CC);
+ closure_is_static = op_array->common.fn_flags & ZEND_ACC_STATIC;
+ closure_is_being_defined_inside_static_context = EX(prev_execute_data) && EX(prev_execute_data)->function_state.function->common.fn_flags & ZEND_ACC_STATIC;
+ if (closure_is_static || closure_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();