Skip to content

Commit 6d71d98

Browse files
committed
Merge branch 'PHP-7.4'
2 parents 9b7a78b + d1e5006 commit 6d71d98

19 files changed

+55
-23
lines changed

Zend/tests/bug61970_1.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class Bar extends Foo {
1111
protected function __construct(){}
1212
}
1313
--EXPECTF--
14-
Fatal error: Access level to Bar::__construct() must be public (as in class Foo) in %s
14+
Fatal error: Access level to Bar::__construct() must be public (as in class Foo) in %s on line 8

Zend/tests/bug61970_2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ class Baz extends Bar {
1515
protected function __construct(){}
1616
}
1717
--EXPECTF--
18-
Fatal error: Access level to Baz::__construct() must be public (as in class Bar) in %s
18+
Fatal error: Access level to Baz::__construct() must be public (as in class Bar) in %s on line 12

Zend/tests/bug62814.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class C extends B {
1717

1818
?>
1919
--EXPECTF--
20-
Fatal error: Access level to C::test() must be protected (as in class B) or weaker in %s on line %d
20+
Fatal error: Access level to C::test() must be protected (as in class B) or weaker in %s on line 12

Zend/tests/inter_007.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ interface a extends d, w { }
1717

1818
?>
1919
--EXPECTF--
20-
Fatal error: Cannot make non static method c::B() static in class d in %s on line %d
20+
Fatal error: Cannot make non static method c::B() static in class d in %s on line 4

Zend/tests/magic_methods_008.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class a extends b {
1616
--EXPECTF--
1717
Warning: The magic method __set() must have public visibility and cannot be static in %s on line %d
1818

19-
Fatal error: Access level to a::__set() must be public (as in class b) in %s on line %d
19+
Fatal error: Access level to a::__set() must be public (as in class b) in %s on line 8

Zend/zend.c

+18
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,24 @@ ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) {
14621462
va_end(args);
14631463
}
14641464

1465+
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
1466+
int type, const char *filename, uint32_t lineno, const char *format, ...)
1467+
{
1468+
va_list args;
1469+
1470+
if (!filename) {
1471+
uint32_t dummy_lineno;
1472+
get_filename_lineno(type, &filename, &dummy_lineno);
1473+
}
1474+
1475+
va_start(args, format);
1476+
zend_error_va_list(type, filename, lineno, format, args);
1477+
va_end(args);
1478+
/* Should never reach this. */
1479+
abort();
1480+
}
1481+
/* }}} */
1482+
14651483
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
14661484
{
14671485
const char *filename;

Zend/zend.h

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRI
296296
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
297297
/* If filename is NULL the default filename is used. */
298298
ZEND_API ZEND_COLD void zend_error_at(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
299+
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
299300

300301
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
301302
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);

Zend/zend_inheritance.c

+20-7
Original file line numberDiff line numberDiff line change
@@ -546,29 +546,41 @@ static ZEND_COLD zend_string *zend_get_function_declaration(const zend_function
546546
}
547547
/* }}} */
548548

549+
static zend_always_inline uint32_t func_lineno(zend_function *fn) {
550+
return fn->common.type == ZEND_USER_FUNCTION ? fn->op_array.line_start : 0;
551+
}
552+
549553
static void do_inheritance_check_on_method(zend_function *child, zend_function *parent, zend_class_entry *ce, zval *child_zv) /* {{{ */
550554
{
551555
uint32_t child_flags;
552556
uint32_t parent_flags = parent->common.fn_flags;
553557

554558
if (UNEXPECTED(parent_flags & ZEND_ACC_FINAL)) {
555-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot override final method %s::%s()", ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name));
559+
zend_error_at_noreturn(E_COMPILE_ERROR, NULL, func_lineno(child),
560+
"Cannot override final method %s::%s()",
561+
ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name));
556562
}
557563

558564
child_flags = child->common.fn_flags;
559565
/* You cannot change from static to non static and vice versa.
560566
*/
561567
if (UNEXPECTED((child_flags & ZEND_ACC_STATIC) != (parent_flags & ZEND_ACC_STATIC))) {
562568
if (child_flags & ZEND_ACC_STATIC) {
563-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot make non static method %s::%s() static in class %s", ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name), ZEND_FN_SCOPE_NAME(child));
569+
zend_error_at_noreturn(E_COMPILE_ERROR, NULL, func_lineno(child),
570+
"Cannot make non static method %s::%s() static in class %s",
571+
ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name), ZEND_FN_SCOPE_NAME(child));
564572
} else {
565-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot make static method %s::%s() non static in class %s", ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name), ZEND_FN_SCOPE_NAME(child));
573+
zend_error_at_noreturn(E_COMPILE_ERROR, NULL, func_lineno(child),
574+
"Cannot make static method %s::%s() non static in class %s",
575+
ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name), ZEND_FN_SCOPE_NAME(child));
566576
}
567577
}
568578

569579
/* Disallow making an inherited method abstract. */
570580
if (UNEXPECTED((child_flags & ZEND_ACC_ABSTRACT) > (parent_flags & ZEND_ACC_ABSTRACT))) {
571-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot make non abstract method %s::%s() abstract in class %s", ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name), ZEND_FN_SCOPE_NAME(child));
581+
zend_error_at_noreturn(E_COMPILE_ERROR, NULL, func_lineno(child),
582+
"Cannot make non abstract method %s::%s() abstract in class %s",
583+
ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name), ZEND_FN_SCOPE_NAME(child));
572584
}
573585

574586
if (parent_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_CHANGED)) {
@@ -615,7 +627,9 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
615627
}
616628
/* Prevent derived classes from restricting access that was available in parent classes (except deriving from non-abstract ctors) */
617629
if ((child_flags & ZEND_ACC_PPP_MASK) > (parent_flags & ZEND_ACC_PPP_MASK)) {
618-
zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::%s() must be %s (as in class %s)%s", ZEND_FN_SCOPE_NAME(child), ZSTR_VAL(child->common.function_name), zend_visibility_string(parent_flags), ZEND_FN_SCOPE_NAME(parent), (parent_flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
630+
zend_error_at_noreturn(E_COMPILE_ERROR, NULL, func_lineno(child),
631+
"Access level to %s::%s() must be %s (as in class %s)%s",
632+
ZEND_FN_SCOPE_NAME(child), ZSTR_VAL(child->common.function_name), zend_visibility_string(parent_flags), ZEND_FN_SCOPE_NAME(parent), (parent_flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
619633
}
620634

621635
if (UNEXPECTED(!zend_do_perform_implementation_check(child, parent))) {
@@ -639,8 +653,7 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
639653
error_level = E_WARNING;
640654
error_verb = "should";
641655
}
642-
zend_error_at(error_level, NULL,
643-
child->common.type == ZEND_USER_FUNCTION ? child->op_array.line_start : 0,
656+
zend_error_at(error_level, NULL, func_lineno(child),
644657
"Declaration of %s %s be compatible with %s",
645658
ZSTR_VAL(child_prototype), error_verb, ZSTR_VAL(method_prototype));
646659
zend_string_efree(child_prototype);

tests/classes/clone_005.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class test extends base {
1616

1717
?>
1818
--EXPECTF--
19-
Fatal error: Cannot override final method base::__clone() in %sclone_005.php on line %d
19+
Fatal error: Cannot override final method base::__clone() in %sclone_005.php on line 11

tests/classes/final_redeclare.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class fail extends pass {
2020
echo "Done\n"; // Shouldn't be displayed
2121
?>
2222
--EXPECTF--
23-
Fatal error: Cannot override final method pass::show() in %s on line %d
23+
Fatal error: Cannot override final method pass::show() in %s on line 12

tests/classes/static_mix_1.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ fail::show();
2121
echo "Done\n"; // shouldn't be displayed
2222
?>
2323
--EXPECTF--
24-
Fatal error: Cannot make static method pass::show() non static in class fail in %s on line %d
24+
Fatal error: Cannot make static method pass::show() non static in class fail in %s on line 10

tests/classes/static_mix_2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ fail::show();
2222
echo "Done\n"; // shouldn't be displayed
2323
?>
2424
--EXPECTF--
25-
Fatal error: Cannot make non static method pass::show() static in class fail in %s on line %d
25+
Fatal error: Cannot make non static method pass::show() static in class fail in %s on line 10

tests/classes/visibility_000a.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class fail extends same {
2828
echo "Done\n"; // shouldn't be displayed
2929
?>
3030
--EXPECTF--
31-
Fatal error: Access level to fail::f0() must be public (as in class same) in %s on line %d
31+
Fatal error: Access level to fail::f0() must be public (as in class same) in %s on line 22

tests/classes/visibility_000b.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class fail extends same {
2828
echo "Done\n"; // shouldn't be displayed
2929
?>
3030
--EXPECTF--
31-
Fatal error: Access level to fail::f0() must be public (as in class same) in %s on line %d
31+
Fatal error: Access level to fail::f0() must be public (as in class same) in %s on line 22

tests/classes/visibility_001a.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class fail extends same {
2828
echo "Done\n"; // shouldn't be displayed
2929
?>
3030
--EXPECTF--
31-
Fatal error: Access level to fail::f1() must be public (as in class same) in %s on line %d
31+
Fatal error: Access level to fail::f1() must be public (as in class same) in %s on line 22

tests/classes/visibility_001b.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class fail extends same {
2828
echo "Done\n"; // shouldn't be displayed
2929
?>
3030
--EXPECTF--
31-
Fatal error: Access level to fail::f1() must be public (as in class same) in %s on line %d
31+
Fatal error: Access level to fail::f1() must be public (as in class same) in %s on line 22

tests/classes/visibility_002a.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class fail extends same {
2828
echo "Done\n"; // shouldn't be displayed
2929
?>
3030
--EXPECTF--
31-
Fatal error: Access level to fail::f2() must be public (as in class same) in %s on line %d
31+
Fatal error: Access level to fail::f2() must be public (as in class same) in %s on line 22

tests/classes/visibility_002b.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class fail extends same {
2828
echo "Done\n"; // shouldn't be displayed
2929
?>
3030
--EXPECTF--
31-
Fatal error: Access level to fail::f2() must be public (as in class same) in %s on line %d
31+
Fatal error: Access level to fail::f2() must be public (as in class same) in %s on line 22

tests/classes/visibility_003b.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class fail extends same {
2828
echo "Done\n"; // shouldn't be displayed
2929
?>
3030
--EXPECTF--
31-
Fatal error: Access level to fail::f3() must be protected (as in class same) or weaker in %s on line %d
31+
Fatal error: Access level to fail::f3() must be protected (as in class same) or weaker in %s on line 22

0 commit comments

Comments
 (0)