Skip to content

Commit 251f293

Browse files
committed
Make line numbers for inheritance errors more precise
Use the line of the conflicting child method, rather than either the first or last line of the class.
1 parent fd5d659 commit 251f293

13 files changed

+16
-13
lines changed

Zend/tests/bug62358.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ class B extends A {
2323
}
2424
?>
2525
--EXPECTF--
26-
Fatal error: Declaration of B::foo($var) must be compatible with A::foo() in %sbug62358.php on line 17
26+
Fatal error: Declaration of B::foo($var) must be compatible with A::foo() in %sbug62358.php on line 18

Zend/tests/bug64988.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ $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 20
29+
Warning: Declaration of Smooth1::insert(array $data) should be compatible with Noisy1::insert(array $data, $option1 = NULL) in %sbug64988.php on line 17
3030
okey

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 7
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

Zend/tests/object_types/missing_return_type_inheritance_in_class.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class Two extends One {
1111
public function a() {}
1212
}
1313
--EXPECTF--
14-
Fatal error: Declaration of Two::a() must be compatible with One::a(): object in %s on line 9
14+
Fatal error: Declaration of Two::a() must be compatible with One::a(): object in %s on line 8

Zend/tests/return_types/008.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class qux implements foo {
1616
$qux = new qux();
1717
var_dump($qux->bar());
1818
--EXPECTF--
19-
Fatal error: Declaration of qux::bar(): qux must be compatible with foo::bar(): foo in %s008.php on line 7
19+
Fatal error: Declaration of qux::bar(): qux must be compatible with foo::bar(): foo in %s008.php on line 8

Zend/tests/return_types/031.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class B extends A {
1111
?>
1212
DONE
1313
--EXPECTF--
14-
Fatal error: Declaration of B::foo(): ?int must be compatible with A::foo(): int in %s031.php on line 7
14+
Fatal error: Declaration of B::foo(): ?int must be compatible with A::foo(): int in %s031.php on line 6

Zend/tests/return_types/generators003.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class SomeCollection implements Collection {
1717
$some = new SomeCollection();
1818
var_dump($some->getIterator());
1919
--EXPECTF--
20-
Fatal error: Declaration of SomeCollection::getIterator(): Generator must be compatible with Collection::getIterator(): Iterator in %sgenerators003.php on line 6
20+
Fatal error: Declaration of SomeCollection::getIterator(): Generator must be compatible with Collection::getIterator(): Iterator in %sgenerators003.php on line 7

Zend/tests/return_types/inheritance005.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ class Bar extends Foo {
1414
}
1515
}
1616
--EXPECTF--
17-
Fatal error: Declaration of Bar::test(): Bar must be compatible with Foo::test(): Foo in %sinheritance005.php on line 12
17+
Fatal error: Declaration of Bar::test(): Bar must be compatible with Foo::test(): Foo in %sinheritance005.php on line 9

Zend/tests/return_types/inheritance006.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ class Bar extends Foo {
1818
}
1919
}
2020
--EXPECTF--
21-
Fatal error: Declaration of Bar::test(): B must be compatible with Foo::test(): A in %sinheritance006.php on line 14
21+
Fatal error: Declaration of Bar::test(): B must be compatible with Foo::test(): A in %sinheritance006.php on line 11

Zend/tests/return_types/inheritance007.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class Bar extends Foo {
1616
}
1717
}
1818
--EXPECTF--
19-
Fatal error: Declaration of Bar::test(): ArrayObject must be compatible with Foo::test(): Traversable in %sinheritance007.php on line 12
19+
Fatal error: Declaration of Bar::test(): ArrayObject must be compatible with Foo::test(): Traversable in %sinheritance007.php on line 9

Zend/tests/return_types/rfc004.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class UserGateway_MySql implements UserGateway {
1616
}
1717
}
1818
--EXPECTF--
19-
Fatal error: Declaration of UserGateway_MySql::find($id) must be compatible with UserGateway::find($id): User in %s on line 9
19+
Fatal error: Declaration of UserGateway_MySql::find($id) must be compatible with UserGateway::find($id): User in %s on line 11

Zend/zend_inheritance.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,10 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
639639
error_level = E_WARNING;
640640
error_verb = "should";
641641
}
642-
zend_error(error_level, "Declaration of %s %s be compatible with %s", ZSTR_VAL(child_prototype), error_verb, ZSTR_VAL(method_prototype));
642+
zend_error_at(error_level, NULL,
643+
child->common.type == ZEND_USER_FUNCTION ? child->op_array.line_start : 0,
644+
"Declaration of %s %s be compatible with %s",
645+
ZSTR_VAL(child_prototype), error_verb, ZSTR_VAL(method_prototype));
643646
zend_string_efree(child_prototype);
644647
zend_string_efree(method_prototype);
645648
}

ext/opcache/tests/preload_006.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ opcache.preload={PWD}/preload_inheritance_error_ind.inc
1212
echo "Foobar\n";
1313
?>
1414
--EXPECTF--
15-
Fatal error: Declaration of B::foo($bar) must be compatible with A::foo() in %spreload_inheritance_error.inc on line 7
15+
Fatal error: Declaration of B::foo($bar) must be compatible with A::foo() in %spreload_inheritance_error.inc on line 8

0 commit comments

Comments
 (0)