Skip to content

Commit d515455

Browse files
committed
Implement phase 1 of rfc/incompat_ctx
Just changing the error level of the message from E_STRICT to E_DEPRECATED. This comes one version later than the timeline mentioned in the RFC. Oddly, there were no tests for this ‘feature’. I added a simple one.
1 parent 47ee470 commit d515455

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

Zend/tests/incompat_ctx_user.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Incompatible context call (non-internal function)
3+
--INI--
4+
error_reporting=E_ALL
5+
--FILE--
6+
<?php
7+
8+
class A {
9+
function foo() { var_dump(get_class($this)); }
10+
}
11+
class B {
12+
function bar() { A::foo(); }
13+
}
14+
$b = new B;
15+
$b->bar();
16+
17+
?>
18+
--EXPECTF--
19+
Deprecated: Non-static method A::foo() should not be called statically, assuming $this from incompatible context in %s on line %d
20+
string(1) "B"

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMP|VAR|UNUS
26092609
/* We are calling method of the other (incompatible) class,
26102610
but passing $this. This is done for compatibility with php-4. */
26112611
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
2612-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
2612+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
26132613
} else {
26142614
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
26152615
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);

Zend/zend_vm_execute.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,7 +3661,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CONST_HANDLER(
36613661
/* We are calling method of the other (incompatible) class,
36623662
but passing $this. This is done for compatibility with php-4. */
36633663
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
3664-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
3664+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
36653665
} else {
36663666
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
36673667
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -4654,7 +4654,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_TMP_HANDLER(ZE
46544654
/* We are calling method of the other (incompatible) class,
46554655
but passing $this. This is done for compatibility with php-4. */
46564656
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
4657-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
4657+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
46584658
} else {
46594659
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
46604660
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -5512,7 +5512,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_VAR_HANDLER(ZE
55125512
/* We are calling method of the other (incompatible) class,
55135513
but passing $this. This is done for compatibility with php-4. */
55145514
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
5515-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
5515+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
55165516
} else {
55175517
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
55185518
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -6232,7 +6232,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_UNUSED_HANDLER
62326232
/* We are calling method of the other (incompatible) class,
62336233
but passing $this. This is done for compatibility with php-4. */
62346234
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
6235-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
6235+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
62366236
} else {
62376237
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
62386238
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -7092,7 +7092,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CV_HANDLER(ZEN
70927092
/* We are calling method of the other (incompatible) class,
70937093
but passing $this. This is done for compatibility with php-4. */
70947094
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
7095-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
7095+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
70967096
} else {
70977097
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
70987098
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -15561,7 +15561,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZE
1556115561
/* We are calling method of the other (incompatible) class,
1556215562
but passing $this. This is done for compatibility with php-4. */
1556315563
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
15564-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
15564+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
1556515565
} else {
1556615566
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
1556715567
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -17914,7 +17914,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND
1791417914
/* We are calling method of the other (incompatible) class,
1791517915
but passing $this. This is done for compatibility with php-4. */
1791617916
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
17917-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
17917+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
1791817918
} else {
1791917919
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
1792017920
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -20227,7 +20227,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND
2022720227
/* We are calling method of the other (incompatible) class,
2022820228
but passing $this. This is done for compatibility with php-4. */
2022920229
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
20230-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
20230+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
2023120231
} else {
2023220232
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
2023320233
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -21667,7 +21667,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_UNUSED_HANDLER(Z
2166721667
/* We are calling method of the other (incompatible) class,
2166821668
but passing $this. This is done for compatibility with php-4. */
2166921669
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
21670-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
21670+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
2167121671
} else {
2167221672
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
2167321673
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
@@ -23685,7 +23685,7 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_
2368523685
/* We are calling method of the other (incompatible) class,
2368623686
but passing $this. This is done for compatibility with php-4. */
2368723687
if (call->fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
23688-
zend_error(E_STRICT, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
23688+
zend_error(E_DEPRECATED, "Non-static method %s::%s() should not be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);
2368923689
} else {
2369023690
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
2369123691
zend_error_noreturn(E_ERROR, "Non-static method %s::%s() cannot be called statically, assuming $this from incompatible context", call->fbc->common.scope->name, call->fbc->common.function_name);

0 commit comments

Comments
 (0)