summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-04-01 11:42:05 +0200
committerNikita Popov <nikic@php.net>2015-04-01 11:42:05 +0200
commit085774997b591c2babbb623fe7102ce2c77bc9fb (patch)
tree5f3e95ed96b203ffdf7c2eff0cfd3e6c5b4208be /Zend
parent7c67727082e6629786c41fbe674f7faf6904d8be (diff)
downloadphp-git-085774997b591c2babbb623fe7102ce2c77bc9fb.tar.gz
Drop support for static calls from incompatible context
Implemented by NULLing $this.
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/bug46381.phpt2
-rw-r--r--Zend/tests/incompat_ctx_user.phpt8
-rw-r--r--Zend/zend_API.c24
-rw-r--r--Zend/zend_vm_def.h21
-rw-r--r--Zend/zend_vm_execute.h168
5 files changed, 92 insertions, 131 deletions
diff --git a/Zend/tests/bug46381.phpt b/Zend/tests/bug46381.phpt
index 6479d0c8a4..92c020b167 100644
--- a/Zend/tests/bug46381.phpt
+++ b/Zend/tests/bug46381.phpt
@@ -14,4 +14,4 @@ $test->method();
echo "Done\n";
?>
--EXPECTF--
-Fatal error: Non-static method ArrayIterator::current() cannot be called statically, assuming $this from incompatible context in %s on line %d
+Fatal error: Non-static method ArrayIterator::current() cannot be called statically in %s on line %d
diff --git a/Zend/tests/incompat_ctx_user.phpt b/Zend/tests/incompat_ctx_user.phpt
index 2d9b59c1e8..f05268cee9 100644
--- a/Zend/tests/incompat_ctx_user.phpt
+++ b/Zend/tests/incompat_ctx_user.phpt
@@ -1,7 +1,5 @@
--TEST--
Incompatible context call (non-internal function)
---INI--
-error_reporting=E_ALL
--FILE--
<?php
@@ -16,5 +14,7 @@ $b->bar();
?>
--EXPECTF--
-Deprecated: Non-static method A::foo() should not be called statically, assuming $this from incompatible context in %s on line %d
-string(1) "B"
+Deprecated: Non-static method A::foo() should not be called statically in %s on line %d
+
+Notice: Undefined variable: this in %s on line %d
+string(1) "A"
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 5a01d546ab..001cb65617 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3108,25 +3108,13 @@ get_function_via_handler:
if ((check_flags & IS_CALLABLE_CHECK_IS_STATIC) != 0) {
retval = 0;
}
- if (EG(current_execute_data) && Z_OBJ(EG(current_execute_data)->This) && instanceof_function(Z_OBJCE(EG(current_execute_data)->This), fcc->calling_scope)) {
- fcc->object = Z_OBJ(EG(current_execute_data)->This);
- if (error) {
- zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb, Z_OBJCE(EG(current_execute_data)->This)->name->val);
- if (severity == E_ERROR) {
- retval = 0;
- }
- } else if (retval) {
- zend_error(severity, "Non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb, Z_OBJCE(EG(current_execute_data)->This)->name->val);
- }
- } else {
- if (error) {
- zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb);
- if (severity == E_ERROR) {
- retval = 0;
- }
- } else if (retval) {
- zend_error(severity, "Non-static method %s::%s() %s be called statically", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb);
+ if (error) {
+ zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb);
+ if (severity == E_ERROR) {
+ retval = 0;
}
+ } else if (retval) {
+ zend_error(severity, "Non-static method %s::%s() %s be called statically", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val, verb);
}
}
if (retval && (check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0) {
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 6e97362922..c8270e8c05 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -2926,27 +2926,24 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMPVAR|UNUSE
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index a9b5a7c300..70035b1cad 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -5065,27 +5065,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
@@ -6989,27 +6986,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
@@ -8473,27 +8467,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
@@ -10020,27 +10011,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
@@ -15880,27 +15868,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
@@ -17453,27 +17438,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
@@ -19068,27 +19050,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}
@@ -20625,27 +20604,24 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
object = NULL;
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
- if (Z_OBJ(EX(This))) {
+ if (Z_OBJ(EX(This)) && instanceof_function(Z_OBJCE(EX(This)), ce)) {
object = Z_OBJ(EX(This));
GC_REFCOUNT(object)++;
}
- if (!object ||
- !instanceof_function(object->ce, ce)) {
- /* We are calling method of the other (incompatible) class,
- but passing $this. This is done for compatibility with php-4. */
+ if (!object) {
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
+ /* Allowed for PHP 4 compatibility. */
zend_error(
E_DEPRECATED,
- "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" : "");
+ "Non-static method %s::%s() should not be called statically",
+ 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. */
+ /* An internal function assumes $this is present and won't check that.
+ * So PHP would crash by allowing the call. */
zend_error(
E_EXCEPTION | 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" : "");
+ "Non-static method %s::%s() cannot be called statically",
+ fbc->common.scope->name->val, fbc->common.function_name->val);
HANDLE_EXCEPTION();
}
}