Skip to content

Commit fd2db11

Browse files
committed
Always generate fatal error for LSP failures
RFC: https://wiki.php.net/rfc/lsp_errors
1 parent 49c4ab3 commit fd2db11

Some content is hidden

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

42 files changed

+143
-186
lines changed

UPGRADING

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ PHP 8.0 UPGRADE NOTES
6666
Additionally, care should be taken that error messages are not displayed in
6767
production environments, which can result in information leaks. Please
6868
ensure that display_errors=Off is used in conjunction with error logging.
69+
. Inheritance errors due to incompatible method signatures (LSP violations)
70+
will now always generate a fatal error. Previously a warning was generated
71+
in some cases.
72+
RFC: https://wiki.php.net/rfc/lsp_errors
6973

7074
- COM:
7175
. Removed the ability to import case-insensitive constants from type

Zend/tests/argument_restriction_001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class Sub extends Base {
1313
}
1414
?>
1515
--EXPECTF--
16-
Warning: Declaration of & Sub::test() should be compatible with & Base::test($foo, array $bar, $option = NULL, $extra = 'llllllllll...') in %sargument_restriction_001.php on line %d
16+
Fatal error: Declaration of & Sub::test() must be compatible with & Base::test($foo, array $bar, $option = NULL, $extra = 'llllllllll...') in %sargument_restriction_001.php on line %d

Zend/tests/argument_restriction_002.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class Sub extends Base {
1313
}
1414
?>
1515
--EXPECTF--
16-
Warning: Declaration of Sub::test($foo, array &$bar) should be compatible with Base::test($foo, array &$bar, $option = NULL, $extra = 3.1415926535898) in %sargument_restriction_002.php on line %d
16+
Fatal error: Declaration of Sub::test($foo, array &$bar) must be compatible with Base::test($foo, array &$bar, $option = NULL, $extra = 3.1415926535898) in %sargument_restriction_002.php on line %d

Zend/tests/argument_restriction_003.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class Sub extends Base {
1616
}
1717
?>
1818
--EXPECTF--
19-
Warning: Declaration of Sub::test() should be compatible with Base::test(Foo $foo, array $bar, $option = NULL, $extra = 'llllllllll...') in %sargument_restriction_003.php on line %d
19+
Fatal error: Declaration of Sub::test() must be compatible with Base::test(Foo $foo, array $bar, $option = NULL, $extra = 'llllllllll...') in %sargument_restriction_003.php on line %d

Zend/tests/argument_restriction_006.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class Sub extends Base {
1313
}
1414
?>
1515
--EXPECTF--
16-
Warning: Declaration of Sub::test($foo, $extra) should be compatible with Base::test($foo, $extra = Array) in %sargument_restriction_006.php on line %d
16+
Fatal error: Declaration of Sub::test($foo, $extra) must be compatible with Base::test($foo, $extra = Array) in %sargument_restriction_006.php on line %d

Zend/tests/bug47981.phpt

-17
This file was deleted.

Zend/tests/bug60573.phpt

+2-28
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,6 @@ public function setSelf(self $s) { }
5353

5454
}
5555

56-
class Foo5 extends Base {
57-
58-
public function setSelf(parent $s) { }
59-
60-
}
61-
62-
class Bar5 extends Foo5 {
63-
64-
public function setSelf(parent $s) { }
65-
66-
}
67-
68-
abstract class Foo6 extends Base {
69-
70-
abstract public function setSelf(parent $s);
71-
72-
}
73-
74-
class Bar6 extends Foo6 {
75-
76-
public function setSelf(Foo6 $s) { }
77-
78-
}
56+
?>
7957
--EXPECTF--
80-
Warning: Declaration of Bar4::setSelf(Bar4 $s) should be compatible with Foo4::setSelf(Foo4 $s) in %sbug60573.php on line %d
81-
82-
Warning: Declaration of Bar5::setSelf(Foo5 $s) should be compatible with Foo5::setSelf(Base $s) in %sbug60573.php on line %d
83-
84-
Fatal error: Declaration of Bar6::setSelf(Foo6 $s) must be compatible with Foo6::setSelf(Base $s) in %sbug60573.php on line %d
58+
Fatal error: Declaration of Bar4::setSelf(Bar4 $s) must be compatible with Foo4::setSelf(Foo4 $s) in %s on line %d

Zend/tests/bug60573_2.phpt

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
Bug #60573 (type hinting with "self" keyword causes weird errors) -- variation 2
3+
--FILE--
4+
<?php
5+
class Foo1 {
6+
7+
public function setSelf(self $s) { }
8+
9+
}
10+
11+
class Bar1 extends Foo1 {
12+
13+
public function setSelf(parent $s) { }
14+
15+
}
16+
17+
class Foo2 {
18+
19+
public function setSelf(Foo2 $s) { }
20+
21+
}
22+
23+
class Bar2 extends Foo2 {
24+
25+
public function setSelf(parent $s) { }
26+
27+
}
28+
29+
class Base {
30+
}
31+
32+
class Foo3 extends Base{
33+
34+
public function setSelf(parent $s) { }
35+
36+
}
37+
38+
class Bar3 extends Foo3 {
39+
40+
public function setSelf(Base $s) { }
41+
42+
}
43+
44+
class Foo4 {
45+
46+
public function setSelf(self $s) { }
47+
48+
}
49+
50+
class Foo5 extends Base {
51+
52+
public function setSelf(parent $s) { }
53+
54+
}
55+
56+
class Bar5 extends Foo5 {
57+
58+
public function setSelf(parent $s) { }
59+
60+
}
61+
62+
?>
63+
--EXPECTF--
64+
Fatal error: Declaration of Bar5::setSelf(Foo5 $s) must be compatible with Foo5::setSelf(Base $s) in %sbug60573_2.php on line %d

Zend/tests/bug63336.phpt

-22
This file was deleted.

Zend/tests/bug64988.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ $o = new Smooth1();
2626
echo "okey";
2727
?>
2828
--EXPECTF--
29-
Warning: Declaration of Smooth1::insert(array $data) should be compatible with Noisy1::insert(array $data, $option1 = NULL) in %sbug64988.php on line 17
30-
okey
29+
Fatal error: Declaration of Smooth1::insert(array $data) must be compatible with Noisy1::insert(array $data, $option1 = NULL) in %sbug64988.php on line 17

Zend/tests/bug65322.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ set_error_handler(function($_, $msg, $file) {
1515

1616
/* This is just a particular example of a non-fatal compile-time error
1717
* If this breaks in future, just find another example and use it instead */
18-
eval('class A { function test() { } } class B extends A { function test($a) { } }');
18+
eval('class A { private function __invoke() { } }');
1919

2020
?>
2121
--EXPECTF--
22-
string(62) "Declaration of B::test($a) should be compatible with A::test()"
22+
string(76) "The magic method __invoke() must have public visibility and cannot be static"
2323
string(%d) "%s(%d) : eval()'d code"
2424
string(1) "X"

Zend/tests/bug67436/b.inc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

33
class b extends a {
4-
public function test() {
4+
private function __invoke() {}
5+
6+
public function test($arg = c::TESTCONSTANT) {
57
echo __METHOD__ . "()\n";
68
parent::test();
79
}

Zend/tests/bug67436/bug67436.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
bug67436: Autoloader isn't called if user defined error handler is present
33
--INI--
44
error_reporting=-1
5+
--SKIPIF--
6+
<?php if (extension_loaded('Zend OPCache')) die('skip Opcache overrides error handler'); ?>
57
--FILE--
68
<?php
79

@@ -12,12 +14,14 @@ spl_autoload_register(function($classname) {
1214
});
1315

1416
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
17+
var_dump($errstr);
1518
}, error_reporting());
1619

1720
a::staticTest();
1821

1922
$b = new b();
2023
$b->test();
2124
--EXPECT--
25+
string(76) "The magic method __invoke() must have public visibility and cannot be static"
2226
b::test()
2327
a::test(c::TESTCONSTANT)

Zend/tests/bug67436/bug67436_nohandler.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ a::staticTest();
1414
$b = new b();
1515
$b->test();
1616
--EXPECTF--
17-
Warning: Declaration of b::test() should be compatible with a::test($arg = c::TESTCONSTANT) in %s%ebug67436%eb.inc on line %d
17+
Warning: The magic method __invoke() must have public visibility and cannot be static in %s on line %d
1818
b::test()
1919
a::test(c::TESTCONSTANT)

Zend/tests/bug70957.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class B extends Foo
1919
}
2020
?>
2121
--EXPECTF--
22-
Warning: Declaration of T::bar() should be compatible with Foo::bar($a = 'Foo') in %sbug70957.php on line %d
22+
Fatal error: Declaration of T::bar() must be compatible with Foo::bar($a = 'Foo') in %sbug70957.php on line %d

Zend/tests/bug71428.1.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class B extends A {
99
public function m(array $a = []) {}
1010
}
1111
--EXPECTF--
12-
Warning: Declaration of B::m(array $a = Array) should be compatible with A::m(?array $a = NULL) in %sbug71428.1.php on line 6
12+
Fatal error: Declaration of B::m(array $a = Array) must be compatible with A::m(?array $a = NULL) in %sbug71428.1.php on line 6

Zend/tests/bug71428.3.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ class B { public function m(A $a = NULL, $n) { echo "B.m";} };
77
class C extends B { public function m(A $a , $n) { echo "C.m";} };
88
?>
99
--EXPECTF--
10-
Warning: Declaration of C::m(A $a, $n) should be compatible with B::m(?A $a, $n) in %sbug71428.3.php on line 4
10+
Fatal error: Declaration of C::m(A $a, $n) must be compatible with B::m(?A $a, $n) in %sbug71428.3.php on line 4

Zend/tests/errmsg_045.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ set_error_handler(function($_, $msg, $file) {
1010

1111
/* This is just a particular example of a non-fatal compile-time error
1212
* If this breaks in future, just find another example and use it instead */
13-
eval('class A { function test() { } } class B extends A { function test($a) { } }');
13+
eval('class A { private function __invoke() { } }');
1414

1515
?>
1616
--EXPECTF--
17-
string(62) "Declaration of B::test($a) should be compatible with A::test()"
17+
string(76) "The magic method __invoke() must have public visibility and cannot be static"
1818
string(%d) "%s(%d) : eval()'d code"
1919

2020
Notice: Undefined variable: undefined in %s on line %d

Zend/tests/objects_002.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class test3 extends test {
1717
function foo($arg) {}
1818
}
1919

20-
echo "Done\n";
2120
?>
2221
--EXPECTF--
23-
Warning: Declaration of test3::foo($arg) should be compatible with test::foo() in %s on line %d
24-
Done
22+
Fatal error: Declaration of test3::foo($arg) must be compatible with test::foo() in %s on line %d

Zend/tests/objects_003.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class test3 extends test {
1717
function foo($arg, $arg2) {}
1818
}
1919

20-
echo "Done\n";
2120
?>
2221
--EXPECTF--
23-
Warning: Declaration of test3::foo($arg, $arg2) should be compatible with test::foo($arg) in %s on line %d
24-
Done
22+
Fatal error: Declaration of test3::foo($arg, $arg2) must be compatible with test::foo($arg) in %s on line %d

Zend/tests/objects_004.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class test3 extends test {
1717
function foo(&$arg) {}
1818
}
1919

20-
echo "Done\n";
2120
?>
2221
--EXPECTF--
23-
Warning: Declaration of test3::foo(&$arg) should be compatible with test::foo($arg) in %s on line %d
24-
Done
22+
Fatal error: Declaration of test3::foo(&$arg) must be compatible with test::foo($arg) in %s on line %d

Zend/tests/objects_005.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class test3 extends test {
1717
function foo() {}
1818
}
1919

20-
echo "Done\n";
2120
?>
2221
--EXPECTF--
23-
Warning: Declaration of test3::foo() should be compatible with & test::foo() in %s on line %d
24-
Done
22+
Fatal error: Declaration of test3::foo() must be compatible with & test::foo() in %s on line %d

Zend/tests/objects_006.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class test3 extends test {
1717
function foo($arg, $arg2) {}
1818
}
1919

20-
echo "Done\n";
2120
?>
2221
--EXPECTF--
23-
Warning: Declaration of test3::foo($arg, $arg2) should be compatible with test::foo($arg, $arg2 = NULL) in %s on line %d
24-
Done
22+
Fatal error: Declaration of test3::foo($arg, $arg2) must be compatible with test::foo($arg, $arg2 = NULL) in %s on line %d

Zend/tests/objects_007.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class test3 extends test {
1717
function foo($arg, &$arg2) {}
1818
}
1919

20-
echo "Done\n";
2120
?>
2221
--EXPECTF--
23-
Warning: Declaration of test3::foo($arg, &$arg2) should be compatible with test::foo($arg, &$arg2 = NULL) in %s on line %d
24-
Done
22+
Fatal error: Declaration of test3::foo($arg, &$arg2) must be compatible with test::foo($arg, &$arg2 = NULL) in %s on line %d

Zend/tests/objects_008.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class test3 extends test {
1717
function foo(Test3 $arg) {}
1818
}
1919

20-
echo "Done\n";
2120
?>
2221
--EXPECTF--
23-
Warning: Declaration of test3::foo(Test3 $arg) should be compatible with test::foo(Test $arg) in %s on line %d
24-
Done
22+
Fatal error: Declaration of test3::foo(Test3 $arg) must be compatible with test::foo(Test $arg) in %s on line %d

Zend/tests/return_types/bug71978.phpt

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
Bug #71978 (Existence of return type hint affects other compatibility rules)
33
--FILE--
44
<?php
5-
class A {
6-
function foo(int $a) {}
7-
}
8-
class B extends A {
9-
function foo(string $a) {}
10-
}
115
class A1 {
126
function foo(int $a): int {}
137
}
@@ -16,6 +10,4 @@ class B1 extends A1 {
1610
}
1711
?>
1812
--EXPECTF--
19-
Warning: Declaration of B::foo(string $a) should be compatible with A::foo(int $a) in %s on line %d
20-
21-
Warning: Declaration of B1::foo(string $a): int should be compatible with A1::foo(int $a): int in %s on line %d
13+
Fatal error: Declaration of B1::foo(string $a): int must be compatible with A1::foo(int $a): int in %s on line %d

Zend/tests/type_declarations/iterable_004.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ class Bar extends Foo {
2121

2222
?>
2323
--EXPECTF--
24-
Warning: Declaration of Bar::testScalar(iterable $iterable) should be compatible with Foo::testScalar(int $int) in %s on line %d
24+
Fatal error: Declaration of Bar::testScalar(iterable $iterable) must be compatible with Foo::testScalar(int $int) in %s on line %d

0 commit comments

Comments
 (0)