Skip to content

Commit 380e705

Browse files
committed
Use consistent line numbers for early binding errors
Non-early-bound classes report inheritance errors at the first line of the class, if no better line information is available (we should really store line numbers for properties at least...) Early bound classes report it at the last line of the class instead. Make the error reporting consistent by always reporting at the first line.
1 parent f78216f commit 380e705

26 files changed

+25
-37
lines changed

Zend/tests/type_declarations/typed_properties_006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class Bar extends Foo {
1111
}
1212
?>
1313
--EXPECTF--
14-
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 8
14+
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 6

Zend/tests/type_declarations/typed_properties_007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ class Bar extends Foo {
1414
}
1515
?>
1616
--EXPECTF--
17-
Fatal error: Type of Bar::$qux must be Whatever (as in class Foo) in %s on line 11
17+
Fatal error: Type of Bar::$qux must be Whatever (as in class Foo) in %s on line 9

Zend/tests/type_declarations/typed_properties_008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class Bar extends Foo {
1111
}
1212
?>
1313
--EXPECTF--
14-
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 8
14+
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 6

Zend/tests/type_declarations/typed_properties_035.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class Baz extends Foo{
1111
}
1212
?>
1313
--EXPECTF--
14-
Fatal error: Type of Baz::$bar must not be defined (as in class Foo) in %s on line 8
14+
Fatal error: Type of Baz::$bar must not be defined (as in class Foo) in %s on line 6

Zend/zend_compile.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7761,13 +7761,10 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{
77617761
&& ((parent_ce->type != ZEND_INTERNAL_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES))
77627762
&& ((parent_ce->type != ZEND_USER_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) || (parent_ce->info.user.filename == ce->info.user.filename))) {
77637763

7764-
CG(zend_lineno) = decl->end_lineno;
77657764
if (zend_try_early_bind(ce, parent_ce, lcname, NULL)) {
7766-
CG(zend_lineno) = ast->lineno;
77677765
zend_string_release(lcname);
77687766
return;
77697767
}
7770-
CG(zend_lineno) = ast->lineno;
77717768
}
77727769
} else if (EXPECTED(zend_hash_add_ptr(CG(class_table), lcname, ce) != NULL)) {
77737770
zend_string_release(lcname);

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3983,16 +3983,7 @@ static void preload_link(void)
39833983
/* Set filename & lineno information for inheritance errors */
39843984
CG(in_compilation) = 1;
39853985
CG(compiled_filename) = ce->info.user.filename;
3986-
if (ce->parent_name
3987-
&& !ce->num_interfaces
3988-
&& !ce->num_traits
3989-
&& (parent->type == ZEND_INTERNAL_CLASS
3990-
|| parent->info.user.filename == ce->info.user.filename)) {
3991-
/* simulate early binding */
3992-
CG(zend_lineno) = ce->info.user.line_end;
3993-
} else {
3994-
CG(zend_lineno) = ce->info.user.line_start;
3995-
}
3986+
CG(zend_lineno) = ce->info.user.line_start;
39963987
ce = zend_do_link_class(ce, NULL, key);
39973988
if (!ce) {
39983989
ZEND_ASSERT(0 && "Class linking failed?");

tests/classes/constants_visibility_error_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ class B extends A {
1212
}
1313
?>
1414
--EXPECTF--
15-
Fatal error: Access level to B::publicConst must be public (as in class A) in %s on line 9
15+
Fatal error: Access level to B::publicConst must be public (as in class A) in %s on line 7

tests/classes/constants_visibility_error_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ class B extends A {
1212
}
1313
?>
1414
--EXPECTF--
15-
Fatal error: Access level to B::protectedConst must be protected (as in class A) or weaker in %s on line 9
15+
Fatal error: Access level to B::protectedConst must be protected (as in class A) or weaker in %s on line 7

tests/classes/property_override_protectedStatic_private.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Redeclare inherited protected static property as private.
2828
$b->showB();
2929
?>
3030
--EXPECTF--
31-
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
31+
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

tests/classes/property_override_protectedStatic_privateStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Redeclare inherited protected static property as private static.
2727
B::showB();
2828
?>
2929
--EXPECTF--
30-
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 18
30+
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 11

tests/classes/property_override_protectedStatic_protected.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Redeclare inherited protected static property as protected.
2828
$b->showB();
2929
?>
3030
--EXPECTF--
31-
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
31+
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

tests/classes/property_override_protectedStatic_public.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Redeclare inherited protected static property as public.
2828
$b->showB();
2929
?>
3030
--EXPECTF--
31-
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
31+
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

tests/classes/property_override_protected_private.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited protected property as private (duplicates Zend/tests/errmsg_
2929
$b->showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 18
32+
Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 11

tests/classes/property_override_protected_privateStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited protected property as private static.
2929
B::showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
32+
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

tests/classes/property_override_protected_protectedStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited protected property as protected static.
2929
B::showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
32+
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

tests/classes/property_override_protected_publicStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited protected property as public static.
2929
B::showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
32+
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

tests/classes/property_override_publicStatic_private.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Redeclare inherited public static property as private.
2828
$b->showB();
2929
?>
3030
--EXPECTF--
31-
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
31+
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

tests/classes/property_override_publicStatic_privateStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Redeclare inherited public static property as private static.
2727
B::showB();
2828
?>
2929
--EXPECTF--
30-
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
30+
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

tests/classes/property_override_publicStatic_protected.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Redeclare inherited public static property as protected.
2828
$b->showB();
2929
?>
3030
--EXPECTF--
31-
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
31+
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

tests/classes/property_override_publicStatic_protectedStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Redeclare inherited public static property as protected static.
2727
B::showB();
2828
?>
2929
--EXPECTF--
30-
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
30+
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

tests/classes/property_override_publicStatic_public.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Redeclare inherited public static property as public.
2828
$b->showB();
2929
?>
3030
--EXPECTF--
31-
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18
31+
Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 11

tests/classes/property_override_public_private.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited public property as private.
2929
$b->showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
32+
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

tests/classes/property_override_public_privateStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited public property as private static.
2929
B::showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
32+
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

tests/classes/property_override_public_protected.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited public property as protected.
2929
$b->showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18
32+
Fatal error: Access level to B::$p must be public (as in class A) in %s on line 11

tests/classes/property_override_public_protectedStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited public property as protected static.
2929
B::showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
32+
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

tests/classes/property_override_public_publicStatic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Redeclare inherited public property as public static.
2929
B::showB();
3030
?>
3131
--EXPECTF--
32-
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18
32+
Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 11

0 commit comments

Comments
 (0)