Skip to content

Commit 214943d

Browse files
committed
Always generate fatal error for LSP failures
1 parent 6d71d98 commit 214943d

40 files changed

+136
-169
lines changed

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 /home/nikic/php-src/Zend/tests/bug60573.php on line 49

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

+2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ spl_autoload_register(function($classname) {
1212
});
1313

1414
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
15+
var_dump($errstr);
1516
}, error_reporting());
1617

1718
a::staticTest();
1819

1920
$b = new b();
2021
$b->test();
2122
--EXPECT--
23+
string(76) "The magic method __invoke() must have public visibility and cannot be static"
2224
b::test()
2325
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-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ class test3 extends test {
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Warning: Declaration of test3::foo($arg) should be compatible with test::foo() in %s on line %d
24-
Done
23+
Fatal error: Declaration of test3::foo($arg) must be compatible with test::foo() in %s on line %d

Zend/tests/objects_003.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ class test3 extends test {
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Warning: Declaration of test3::foo($arg, $arg2) should be compatible with test::foo($arg) in %s on line %d
24-
Done
23+
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-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ class test3 extends test {
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Warning: Declaration of test3::foo(&$arg) should be compatible with test::foo($arg) in %s on line %d
24-
Done
23+
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-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ class test3 extends test {
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Warning: Declaration of test3::foo() should be compatible with & test::foo() in %s on line %d
24-
Done
23+
Fatal error: Declaration of test3::foo() must be compatible with & test::foo() in %s on line %d

Zend/tests/objects_006.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ class test3 extends test {
2020
echo "Done\n";
2121
?>
2222
--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
23+
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-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ class test3 extends test {
2020
echo "Done\n";
2121
?>
2222
--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
23+
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-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ class test3 extends test {
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Warning: Declaration of test3::foo(Test3 $arg) should be compatible with test::foo(Test $arg) in %s on line %d
24-
Done
23+
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
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Parameter variance with no type
2+
Parameter variance with no type (class)
33
--FILE--
44
<?php
55

@@ -8,27 +8,15 @@ class Foo {
88
function testBothClass(Foo $foo) {}
99
function testChildClass($foo) {}
1010
function testNoneClass($foo) {}
11-
12-
function testParentBuiltin(int $foo) {}
13-
function testBothBuiltin(int $foo) {}
14-
function testChildBuiltin($foo) {}
15-
function testNoneBuiltin($foo) {}
1611
}
1712

1813
class Bar extends Foo {
1914
function testParentClass($foo) {}
2015
function testBothClass(Foo $foo) {}
2116
function testChildClass(Foo $foo) {}
2217
function testNoneClass($foo) {}
23-
24-
function testParentBuiltin($foo) {}
25-
function testBothBuiltin(int $foo) {}
26-
function testChildBuiltin(int $foo) {}
27-
function testNoneBuiltin($foo) {}
2818
}
2919

3020
?>
3121
--EXPECTF--
32-
Warning: Declaration of Bar::testChildClass(Foo $foo) should be compatible with Foo::testChildClass($foo) in %s on line %d
33-
34-
Warning: Declaration of Bar::testChildBuiltin(int $foo) should be compatible with Foo::testChildBuiltin($foo) in %s on line %d
22+
Fatal error: Declaration of Bar::testChildClass(Foo $foo) must be compatible with Foo::testChildClass($foo) in %s on line %d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Parameter variance with no type (builtin)
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
function testParentBuiltin(int $foo) {}
8+
function testBothBuiltin(int $foo) {}
9+
function testChildBuiltin($foo) {}
10+
function testNoneBuiltin($foo) {}
11+
}
12+
13+
class Bar extends Foo {
14+
function testParentBuiltin($foo) {}
15+
function testBothBuiltin(int $foo) {}
16+
function testChildBuiltin(int $foo) {}
17+
function testNoneBuiltin($foo) {}
18+
}
19+
20+
?>
21+
--EXPECTF--
22+
Fatal error: Declaration of Bar::testChildBuiltin(int $foo) must be compatible with Foo::testChildBuiltin($foo) in %s on line %d

0 commit comments

Comments
 (0)