com php-src: Moved checks and error reporting related to static methods from DO_FCALL inti INTI_FCALL* opcodes that may really deal with static
methods. (In some rare cases it may lead to different order of warning messages).: Zend/zend_vm_def.h Zend/z end_vm_execute.h
tests/lang/passByReference_005 .phpt

From: Date: Sat, 04 Oct 2014 10:55:44 +0000
Subject: com php-src: Moved checks and error reporting related to static methods from DO_FCALL inti INTI_FCALL* opcodes that may really deal with static
methods. (In some rare cases it may lead to different order of warning messages).: Zend/zend_vm_def.h Zend/z end_vm_execute.h
tests/lang/passByReference_005 .phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-82092@lists.php.net to get a copy of this message
Commit: 2e1b8ba4b797388265ca4bec5be0fa31584a1323 Author: Dmitry Stogov <dmitry@zend.com> Sat, 4 Oct 2014 14:55:44 +0400 Parents: f1e21c4979f215112f9a30bc9e6e4a1ebd5a32de Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2e1b8ba4b797388265ca4bec5be0fa31584a1323 Log: Moved checks and error reporting related to static methods from DO_FCALL inti INTI_FCALL* opcodes that may really deal with static methods. (In some rare cases it may lead to different order of warning messages). Changed paths: M Zend/zend_vm_def.h M Zend/zend_vm_execute.h M tests/lang/passByReference_005.phpt

diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 7fa544b..d87b1e4 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2261,16 +2261,25 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMP|VAR|UNUS if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -2396,6 +2405,18 @@ ZEND_VM_HANDLER(59, ZEND_INIT_FCALL_BY_NAME, ANY, CONST|TMP|VAR|CV) if (UNEXPECTED(fbc == NULL)) { zend_error_noreturn(E_ERROR, "Call to undefined method %s::%s()", called_scope->name->val, Z_STRVAL_P(method)); } + if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) { + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } + } } else { called_scope = Z_OBJCE_P(obj); object = Z_OBJ_P(obj); @@ -2452,6 +2473,18 @@ ZEND_VM_HANDLER(118, ZEND_INIT_USER_CALL, CONST, CONST|TMP|VAR|CV) object = fcc.object; if (object) { GC_REFCOUNT(object)++; /* For $this pointer */ + } else if (func->common.scope && + !(func->common.fn_flags & ZEND_ACC_STATIC)) { + if (func->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + func->common.scope->name->val, func->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + func->common.scope->name->val, func->common.function_name->val); + } } } else { zend_error(E_WARNING, "%s() expects parameter 1 to be a valid callback, %s", Z_STRVAL_P(opline->op1.zv), error); @@ -2548,22 +2581,6 @@ ZEND_VM_HANDLER(60, ZEND_DO_FCALL, ANY, ANY) } } } - if (fbc->common.scope && - !(fbc->common.fn_flags & ZEND_ACC_STATIC) && - !object) { - - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - /* FIXME: output identifiers properly */ - zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically", fbc->common.scope->name->val, fbc->common.function_name->val); - if (UNEXPECTED(EG(exception) != NULL)) { - HANDLE_EXCEPTION(); - } - } else { - /* FIXME: output identifiers properly */ - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically", fbc->common.scope->name->val, fbc->common.function_name->val); - } - } LOAD_OPLINE(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 9f7d4c3..543c1c2 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -509,22 +509,6 @@ static int ZEND_FASTCALL ZEND_DO_FCALL_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) } } } - if (fbc->common.scope && - !(fbc->common.fn_flags & ZEND_ACC_STATIC) && - !object) { - - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - /* FIXME: output identifiers properly */ - zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically", fbc->common.scope->name->val, fbc->common.function_name->val); - if (UNEXPECTED(EG(exception) != NULL)) { - HANDLE_EXCEPTION(); - } - } else { - /* FIXME: output identifiers properly */ - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically", fbc->common.scope->name->val, fbc->common.function_name->val); - } - } LOAD_OPLINE(); @@ -1606,6 +1590,18 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_CONST_HANDLER(ZEND_OPCODE if (UNEXPECTED(fbc == NULL)) { zend_error_noreturn(E_ERROR, "Call to undefined method %s::%s()", called_scope->name->val, Z_STRVAL_P(method)); } + if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) { + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } + } } else { called_scope = Z_OBJCE_P(obj); object = Z_OBJ_P(obj); @@ -1931,6 +1927,18 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_TMP_HANDLER(ZEND_OPCODE_H if (UNEXPECTED(fbc == NULL)) { zend_error_noreturn(E_ERROR, "Call to undefined method %s::%s()", called_scope->name->val, Z_STRVAL_P(method)); } + if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) { + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } + } } else { called_scope = Z_OBJCE_P(obj); object = Z_OBJ_P(obj); @@ -2105,6 +2113,18 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_VAR_HANDLER(ZEND_OPCODE_H if (UNEXPECTED(fbc == NULL)) { zend_error_noreturn(E_ERROR, "Call to undefined method %s::%s()", called_scope->name->val, Z_STRVAL_P(method)); } + if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) { + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } + } } else { called_scope = Z_OBJCE_P(obj); object = Z_OBJ_P(obj); @@ -2316,6 +2336,18 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_CV_HANDLER(ZEND_OPCODE_HA if (UNEXPECTED(fbc == NULL)) { zend_error_noreturn(E_ERROR, "Call to undefined method %s::%s()", called_scope->name->val, Z_STRVAL_P(method)); } + if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) { + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + fbc->common.scope->name->val, fbc->common.function_name->val); + } + } } else { called_scope = Z_OBJCE_P(obj); object = Z_OBJ_P(obj); @@ -4129,16 +4161,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CONST_HANDLER( if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -4186,6 +4227,18 @@ static int ZEND_FASTCALL ZEND_INIT_USER_CALL_SPEC_CONST_CONST_HANDLER(ZEND_OPCO object = fcc.object; if (object) { GC_REFCOUNT(object)++; /* For $this pointer */ + } else if (func->common.scope && + !(func->common.fn_flags & ZEND_ACC_STATIC)) { + if (func->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + func->common.scope->name->val, func->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + func->common.scope->name->val, func->common.function_name->val); + } } } else { zend_error(E_WARNING, "%s() expects parameter 1 to be a valid callback, %s", Z_STRVAL_P(opline->op1.zv), error); @@ -5435,16 +5488,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_TMP_HANDLER(ZE if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -5492,6 +5554,18 @@ static int ZEND_FASTCALL ZEND_INIT_USER_CALL_SPEC_CONST_TMP_HANDLER(ZEND_OPCODE object = fcc.object; if (object) { GC_REFCOUNT(object)++; /* For $this pointer */ + } else if (func->common.scope && + !(func->common.fn_flags & ZEND_ACC_STATIC)) { + if (func->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + func->common.scope->name->val, func->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + func->common.scope->name->val, func->common.function_name->val); + } } } else { zend_error(E_WARNING, "%s() expects parameter 1 to be a valid callback, %s", Z_STRVAL_P(opline->op1.zv), error); @@ -6611,16 +6685,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_VAR_HANDLER(ZE if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -6668,6 +6751,18 @@ static int ZEND_FASTCALL ZEND_INIT_USER_CALL_SPEC_CONST_VAR_HANDLER(ZEND_OPCODE object = fcc.object; if (object) { GC_REFCOUNT(object)++; /* For $this pointer */ + } else if (func->common.scope && + !(func->common.fn_flags & ZEND_ACC_STATIC)) { + if (func->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + func->common.scope->name->val, func->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + func->common.scope->name->val, func->common.function_name->val); + } } } else { zend_error(E_WARNING, "%s() expects parameter 1 to be a valid callback, %s", Z_STRVAL_P(opline->op1.zv), error); @@ -7538,16 +7633,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_UNUSED_HANDLER if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -8522,16 +8626,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CV_HANDLER(ZEN if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -8579,6 +8692,18 @@ static int ZEND_FASTCALL ZEND_INIT_USER_CALL_SPEC_CONST_CV_HANDLER(ZEND_OPCODE_ object = fcc.object; if (object) { GC_REFCOUNT(object)++; /* For $this pointer */ + } else if (func->common.scope && + !(func->common.fn_flags & ZEND_ACC_STATIC)) { + if (func->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error(E_STRICT, + "Non-static method %s::%s() should not be called statically", + func->common.scope->name->val, func->common.function_name->val); + } else { + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically", + func->common.scope->name->val, func->common.function_name->val); + } } } else { zend_error(E_WARNING, "%s() expects parameter 1 to be a valid callback, %s", Z_STRVAL_P(opline->op1.zv), error); @@ -18536,16 +18661,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZE if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -20752,16 +20886,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -22934,16 +23077,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -24401,16 +24553,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_UNUSED_HANDLER(Z if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } @@ -26302,16 +26463,25 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_ if (Z_OBJ(EX(This))) { object = Z_OBJ(EX(This)); GC_REFCOUNT(object)++; - if (object->handlers->get_class_entry && - !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC)) { - /* We are calling method of the other (incompatible) class, - but passing $this. This is done for compatibility with php-4. */ - if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { - zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } else { - /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ - zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", fbc->common.scope->name->val, fbc->common.function_name->val); - } + } + if (!object || + (object->handlers->get_class_entry && + !instanceof_function(zend_get_class_entry(object TSRMLS_CC), ce TSRMLS_CC))) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) { + zend_error( + object ? E_DEPRECATED : E_STRICT, + "Non-static method %s::%s() should not be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); + } else { + /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */ + zend_error_noreturn( + E_ERROR, + "Non-static method %s::%s() cannot be called statically%s", + fbc->common.scope->name->val, fbc->common.function_name->val, + object ? ", assuming $this from incompatible context" : ""); } } } diff --git a/tests/lang/passByReference_005.phpt b/tests/lang/passByReference_005.phpt index 52ddeeb..b90f0ce 100644 --- a/tests/lang/passByReference_005.phpt +++ b/tests/lang/passByReference_005.phpt @@ -144,7 +144,7 @@ var_dump($u1, $u2); ?> --EXPECTF-- - ---- Pass by ref / pass by val: functions ---- +---- Pass by ref / pass by val: functions ---- Notice: Undefined variable: u1 in %s on line 72 @@ -179,40 +179,40 @@ string(12) "Ref2 changed" ---- Pass by ref / pass by val: static method calls ---- -Notice: Undefined variable: u1 in %s on line 95 - Strict Standards: Non-static method C::v() should not be called statically in %s on line 95 +Notice: Undefined variable: u1 in %s on line 95 + Strict Standards: Non-static method C::r() should not be called statically in %s on line 96 Notice: Undefined variable: u1 in %s on line 97 NULL string(11) "Ref changed" +Strict Standards: Non-static method C::vv() should not be called statically in %s on line 100 + Notice: Undefined variable: u1 in %s on line 100 Notice: Undefined variable: u2 in %s on line 100 -Strict Standards: Non-static method C::vv() should not be called statically in %s on line 100 - Notice: Undefined variable: u1 in %s on line 101 Notice: Undefined variable: u2 in %s on line 101 NULL NULL -Notice: Undefined variable: u1 in %s on line 104 - Strict Standards: Non-static method C::vr() should not be called statically in %s on line 104 +Notice: Undefined variable: u1 in %s on line 104 + Notice: Undefined variable: u1 in %s on line 105 NULL string(11) "Ref changed" -Notice: Undefined variable: u2 in %s on line 108 - Strict Standards: Non-static method C::rv() should not be called statically in %s on line 108 +Notice: Undefined variable: u2 in %s on line 108 + Notice: Undefined variable: u2 in %s on line 109 string(11) "Ref changed" NULL @@ -258,4 +258,4 @@ Notice: Undefined variable: u2 in %s on line 135 string(11) "Ref changed" NULL string(12) "Ref1 changed" -string(12) "Ref2 changed" \ No newline at end of file +string(12) "Ref2 changed"
« previous php.cvs (#82092) next »