Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/inheritance/argument_restriction_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class Sub extends Base {
}
?>
--EXPECTF--
Fatal error: Declaration of & Sub::test() must be compatible with & Base::test($foo, array $bar, $option = null, $extra = 'llllllllll...') in %s on line %d
Fatal error: Declaration of Sub::&test() must be compatible with Base::&test($foo, array $bar, $option = null, $extra = 'llllllllll...') in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/objects/objects_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class test3 extends test {

?>
--EXPECTF--
Fatal error: Declaration of test3::foo() must be compatible with & test::foo() in %s on line %d
Fatal error: Declaration of test3::foo() must be compatible with test::&foo() in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class A implements I {

?>
--EXPECTF--
Fatal error: Declaration of A::$prop::get() must be compatible with & I::$prop::get() in %s on line %d
Fatal error: Declaration of A::$prop::get() must be compatible with I::&$prop::get() in %s on line %d
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks weird, as the signature of reference get hook is &get, not &$prop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had also seen that. This isn't quite trivial to fix, since it the technical method name is $prop::get as a single string. Moving the & in front of the class name (just removing the space) would work. My main issue is with the space.

/cc @Crell @iluuu1994

Copy link
Member

@iluuu1994 iluuu1994 Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what I think of this change, but I::$prop::&get() seems like the consistent option. I don't think I::&$prop::get() is better than what we currently have. But I also acknowledge this is likely not important enough to warrant a complex fix.

I think overall I'd prefer not to adjust the message at all (apart from maybe removing the space).

8 changes: 4 additions & 4 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,6 @@ static ZEND_COLD zend_string *zend_get_function_declaration(
{
smart_str str = {0};

if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
smart_str_appends(&str, "& ");
}

if (fptr->common.scope) {
if (fptr->common.scope->ce_flags & ZEND_ACC_ANON_CLASS) {
/* cut off on NULL byte ... class@anonymous */
Expand All @@ -929,6 +925,10 @@ static ZEND_COLD zend_string *zend_get_function_declaration(
smart_str_appends(&str, "::");
}

if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
smart_str_appendc(&str, '&');
}

smart_str_append(&str, fptr->common.function_name);
smart_str_appendc(&str, '(');

Expand Down