From: Dmitry Stogov <dmitry@php.net> Date: Wed, 15 Mar 2006 11:12:45 +0000 (+0000) Subject: Added E_STRICT warning in case of calling non-static method from incompatible context... X-Git-Tag: php-5.1.3RC2~106 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f76b17079a709415195a7c27607cd52d039d7c3;p=php Added E_STRICT warning in case of calling non-static method from incompatible context (this feature is staying for BC with php-4). --- diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 85ecccbc85..24d090ece7 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1723,6 +1723,15 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, ANY, CONST|TMP|VAR|UNUSED|CV) if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { + if (OP2_TYPE != IS_UNUSED && + EG(This) && + Z_OBJ_HT_P(EG(This))->get_class_entry && + !instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", EX(fbc)->common.scope->name, EX(fbc)->common.function_name); + + } if ((EX(object) = EG(This))) { EX(object)->refcount++; } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index cf9e1100d5..a9a3c5c2f7 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -678,6 +678,15 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { + if (IS_CONST != IS_UNUSED && + EG(This) && + Z_OBJ_HT_P(EG(This))->get_class_entry && + !instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", EX(fbc)->common.scope->name, EX(fbc)->common.function_name); + + } if ((EX(object) = EG(This))) { EX(object)->refcount++; } @@ -870,6 +879,15 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { + if (IS_TMP_VAR != IS_UNUSED && + EG(This) && + Z_OBJ_HT_P(EG(This))->get_class_entry && + !instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", EX(fbc)->common.scope->name, EX(fbc)->common.function_name); + + } if ((EX(object) = EG(This))) { EX(object)->refcount++; } @@ -1019,6 +1037,15 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { + if (IS_VAR != IS_UNUSED && + EG(This) && + Z_OBJ_HT_P(EG(This))->get_class_entry && + !instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", EX(fbc)->common.scope->name, EX(fbc)->common.function_name); + + } if ((EX(object) = EG(This))) { EX(object)->refcount++; } @@ -1167,6 +1194,15 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { + if (IS_UNUSED != IS_UNUSED && + EG(This) && + Z_OBJ_HT_P(EG(This))->get_class_entry && + !instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", EX(fbc)->common.scope->name, EX(fbc)->common.function_name); + + } if ((EX(object) = EG(This))) { EX(object)->refcount++; } @@ -1248,6 +1284,15 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { + if (IS_CV != IS_UNUSED && + EG(This) && + Z_OBJ_HT_P(EG(This))->get_class_entry && + !instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) { + /* We are calling method of the other (incompatible) class, + but passing $this. This is done for compatibility with php-4. */ + zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", EX(fbc)->common.scope->name, EX(fbc)->common.function_name); + + } if ((EX(object) = EG(This))) { EX(object)->refcount++; }