Skip to content

Commit 6c73b50

Browse files
committed
Remove static calls to non-static methods
1 parent 4eb5db2 commit 6c73b50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+283
-629
lines changed

UPGRADING

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PHP 8.0 UPGRADE NOTES
2323
- Core:
2424
. Methods with the same name as the class are no longer interpreted as
2525
constructors. The __construct() method should be used instead.
26+
. Removed ability to call non-static methods statically.
2627
. Removed (unset) cast.
2728
. Removed track_errors ini directive. This means that $php_errormsg is no
2829
longer available. The error_get_last() function may be used instead.

Zend/tests/009.phpt

-8
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class foo {
1616
class foo2 extends foo {
1717
}
1818

19-
foo::bar();
20-
foo2::bar();
21-
2219
$f1 = new foo;
2320
$f2 = new foo2;
2421

@@ -36,11 +33,6 @@ $f1->testNull();
3633
echo "Done\n";
3734
?>
3835
--EXPECTF--
39-
Deprecated: Non-static method foo::bar() should not be called statically in %s on line %d
40-
string(3) "foo"
41-
42-
Deprecated: Non-static method foo::bar() should not be called statically in %s on line %d
43-
string(3) "foo"
4436
string(3) "foo"
4537
string(3) "foo"
4638

Zend/tests/bug27669.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bug #27669 (PHP 5 didn't support all possibilities for calling static methods dy
33
--FILE--
44
<?php
55
class A {
6-
function hello() {
6+
static function hello() {
77
echo "Hello World\n";
88
}
99
}
@@ -12,6 +12,5 @@ Bug #27669 (PHP 5 didn't support all possibilities for calling static methods dy
1212
?>
1313
===DONE===
1414
--EXPECTF--
15-
Deprecated: Non-static method A::hello() should not be called statically in %s on line %d
1615
Hello World
1716
===DONE===

Zend/tests/bug35437.phpt

-27
This file was deleted.

Zend/tests/bug38047.phpt

-51
This file was deleted.

Zend/tests/bug40621.phpt

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ Foo::get();
1515
echo "Done\n";
1616
?>
1717
--EXPECTF--
18-
Deprecated: Non-static method Foo::get() should not be called statically in %s on line %d
19-
20-
Fatal error: Uncaught Error: Non-static method Foo::__construct() cannot be called statically in %s:%d
18+
Fatal error: Uncaught Error: Non-static method Foo::get() cannot be called statically in %s:%d
2119
Stack trace:
22-
#0 %s(%d): Foo::get()
23-
#1 {main}
20+
#0 {main}
2421
thrown in %s on line %d

Zend/tests/bug47054.phpt

-10
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,10 @@ $c->s();
2424

2525
get_called_class();
2626

27-
D::m();
28-
2927
?>
3028
--EXPECTF--
3129
Called class: D
3230
Called class: C
3331
Called class: C
3432

3533
Warning: get_called_class() called from outside a class in %s on line %d
36-
37-
Deprecated: Non-static method D::m() should not be called statically in %s on line %d
38-
39-
Fatal error: Uncaught Error: Using $this when not in object context in %s:%d
40-
Stack trace:
41-
#0 %s(%d): D::m()
42-
#1 {main}
43-
thrown in %s on line %d

Zend/tests/bug48533.phpt

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ $x->a();
2626
$x->b();
2727
$x->c();
2828
$x::a();
29-
$x::b();
3029
$x::c();
30+
$x::b();
3131

3232
?>
3333
--EXPECTF--
3434
string(9) "__call::a"
3535
int(2)
3636
string(9) "__call::c"
3737
string(15) "__callStatic::a"
38-
39-
Deprecated: Non-static method foo::b() should not be called statically in %s on line %d
40-
int(2)
4138
string(15) "__callStatic::c"
39+
40+
Fatal error: Uncaught Error: Non-static method foo::b() cannot be called statically in %s:%d
41+
Stack trace:
42+
#0 {main}
43+
thrown in %s on line %d

Zend/tests/bug74408.phpt

-34
This file was deleted.

Zend/tests/call_static_006.phpt

-14
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,15 @@ Testing __callStatic
44
<?php
55

66
class foo {
7-
public function aa() {
8-
print "ok\n";
9-
}
107
static function __callstatic($a, $b) {
118
var_dump($a);
129
}
1310
}
1411

15-
foo::aa();
16-
17-
$b = 'AA';
18-
foo::$b();
19-
2012
foo::__construct();
2113

2214
?>
2315
--EXPECTF--
24-
Deprecated: Non-static method foo::aa() should not be called statically in %s on line %d
25-
ok
26-
27-
Deprecated: Non-static method foo::aa() should not be called statically in %s on line %d
28-
ok
29-
3016
Fatal error: Uncaught Error: Cannot call constructor in %s:%d
3117
Stack trace:
3218
#0 {main}

Zend/tests/call_user_func_004.phpt

-22
This file was deleted.

Zend/tests/call_user_func_005.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class foo {
99
return 1;
1010
}
1111

12-
public function teste() {
12+
public static function teste() {
1313
return foo::x(function &($a=1,$b) { });
1414
}
1515
}
@@ -18,7 +18,6 @@ var_dump(call_user_func(array('foo', 'teste')));
1818

1919
?>
2020
--EXPECTF--
21-
Deprecated: %son-static method foo::teste() should not be called statically in %s on line %d
2221
string(1) "x"
2322
array(1) {
2423
[0]=>

Zend/tests/closures/closure_from_callable_non_static_statically.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ try {
1717

1818
?>
1919
--EXPECT--
20-
Failed to create closure from callable: non-static method A::method() should not be called statically
20+
Failed to create closure from callable: non-static method A::method() cannot be called statically

Zend/tests/exception_017.phpt

+12-11
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,29 @@ function foo(callable $x) {
1212
try {
1313
C::foo();
1414
} catch (Error $e) {
15-
echo "\nException: " . $e->getMessage() . " in " , $e->getFile() . " on line " . $e->getLine() . "\n";
15+
echo $e, "\n\n";
1616
}
1717

1818
try {
1919
foo("C::foo");
2020
} catch (Error $e) {
21-
echo "\n";
22-
do {
23-
echo "Exception: " . $e->getMessage() . "\n";
24-
$e = $e->getPrevious();
25-
} while ($e instanceof Error);
21+
echo $e, "\n\n";
2622
}
2723

2824
C::foo();
2925
?>
3026
--EXPECTF--
31-
Exception: Cannot call abstract method C::foo() in %sexception_017.php on line %d
27+
Error: Cannot call abstract method C::foo() in %s:%d
28+
Stack trace:
29+
#0 {main}
30+
31+
TypeError: Argument 1 passed to foo() must be callable, string given, called in %s on line %d and defined in %s:%d
32+
Stack trace:
33+
#0 %s(%d): foo('C::foo')
34+
#1 {main}
3235

33-
Exception: Argument 1 passed to foo() must be callable, string given, called in %sexception_017.php on line %d
34-
Exception: Cannot call abstract method C::foo()
3536

36-
Fatal error: Uncaught Error: Cannot call abstract method C::foo() in %sexception_017.php:%d
37+
Fatal error: Uncaught Error: Cannot call abstract method C::foo() in %s:%d
3738
Stack trace:
3839
#0 {main}
39-
thrown in %sexception_017.php on line %d
40+
thrown in %s on line %d

Zend/tests/fr47160.phpt

-22
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ class Magic3 {
3636
}
3737
}
3838

39-
$f = array('Hello','world');
40-
try {
41-
var_dump($f('you'));
42-
} catch (Throwable $e) {
43-
echo "Exception: " . $e->getMessage() . "\n";
44-
}
45-
try {
46-
var_dump(call_user_func($f, 'you'));
47-
} catch (Throwable $e) {
48-
echo "Exception: " . $e->getMessage() . "\n";
49-
}
50-
51-
printf("-----\n");
52-
5339
$h= new Hello;
5440
$f = array($h,'world');
5541
var_dump($f('again'));
@@ -107,14 +93,6 @@ var_dump(call_user_func($f, 'you'));
10793

10894
?>
10995
--EXPECTF--
110-
Deprecated: Non-static method Hello::world() should not be called statically in %s on line %d
111-
Hello, you
112-
Exception: Using $this when not in object context
113-
114-
Deprecated: %son-static method Hello::world() should not be called statically in %s on line %d
115-
Hello, you
116-
Exception: Using $this when not in object context
117-
-----
11896
Hello, again
11997
object(Hello)#%d (0) {
12098
}

Zend/tests/incompat_ctx_user.phpt

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ Incompatible context call (non-internal function)
44
<?php
55

66
class A {
7-
function foo() { var_dump(get_class($this)); }
7+
function foo() { var_dump(get_class($this)); }
88
}
99
class B {
10-
function bar() { A::foo(); }
10+
function bar() { A::foo(); }
1111
}
1212
$b = new B;
1313
try {
14-
$b->bar();
14+
$b->bar();
1515
} catch (Throwable $e) {
16-
echo "Exception: " . $e->getMessage() . "\n";
16+
echo "Exception: " . $e->getMessage() . "\n";
1717
}
1818
?>
1919
--EXPECTF--
20-
Deprecated: Non-static method A::foo() should not be called statically in %s on line %d
21-
Exception: Using $this when not in object context
20+
Exception: Non-static method A::foo() cannot be called statically

0 commit comments

Comments
 (0)