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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 17 deletions
This file was deleted.

Zend/tests/bug60573.phpt

Lines changed: 2 additions & 28 deletions
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

Lines changed: 64 additions & 0 deletions
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

Lines changed: 0 additions & 22 deletions
This file was deleted.

Zend/tests/bug64988.phpt

Lines changed: 1 addition & 2 deletions
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

0 commit comments

Comments
 (0)