Skip to content

Fix prototype for trait methods #14148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2024
Merged

Fix prototype for trait methods #14148

merged 3 commits into from
May 6, 2024

Conversation

dstogov
Copy link
Member

@dstogov dstogov commented May 6, 2024

Fixes #14009

iluuu1994 and others added 2 commits May 6, 2024 10:42
Remove wierd checks and define the behavior by explicit set of flags
Comment on lines -1905 to +1912
/* Inherited members are overridden by members inserted by traits.
* Check whether the trait method fulfills the inheritance requirements. */
do_inheritance_check_on_method(
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
ce, NULL, /* check_visibility */ 1);
check_inheritance = true;
Copy link
Member Author

Choose a reason for hiding this comment

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

The movement of this call seems not necessary, because the function entry was duplicated into temporary buffer by zend_traits_copy_functions().

I'll verify if it was really necessary for master (see d344fe0)

Copy link
Member Author

Choose a reason for hiding this comment

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

According to my check, this wasn't necessary. So I'm not sure if it's better to keep the call in the old place or move it down.

@TimWolla ^^

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the ping. However I cannot comment meaningfully, due to my lack of expertise on the engine. You are the expert and I trust you here: If all tests pass, then the change is probably fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

@TimWolla the related code was changed so many times, that I spent hours trying to understand all the combinations of conditions... :)

Two questions:

  1. Do you remember why did you move call to do_inheritance_check_on_method_ex() in zend_add_trait_method() down (see commit d344fe0)

  2. I think Zend/tests/attributes/override/016.phpt is wrong. It should emit fatal error, because class C don't have parent method at all.

Copy link
Member

Choose a reason for hiding this comment

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

  1. Do you remember why did you move call to do_inheritance_check_on_method_ex() in zend_add_trait_method() down (see commit d344fe0)

I don't remember exactly. Looking at the commit history of the PR, I made the change in:

f5fd079

The direct parent of it (66a7111) failed the ASAN CI. Unfortunately the logs are no longer available.

However based on that information, I assume that my initial attempt at the fix caused some memory unsafety that I was able to fix by moving the call down. Perhaps a future follow-up (e.g. Ilija's review suggestion) fixed it properly such that the moving of the call is no longer required, I cannot comment on that.

2. I think Zend/tests/attributes/override/016.phpt is wrong. It should emit fatal error, because class C don't have parent method at all.

It does not have a parent method, but its signature is enforced by the abstract method in the trait. This has been voted on as part of the RFC.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does not have a parent method, but its signature is enforced by the abstract method in the trait. This has been voted on as part of the RFC.

OK. I've committed the PRs keeping this behavior.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

Thanks. The changes look good to me. Since they don't fix any new bugs, don't think think it's better to do these for master only?

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

LGTM! I'm still not sure if it's not better to just merge your commit for master. But I'll leave that up to you.

@dstogov
Copy link
Member Author

dstogov commented May 6, 2024

LGTM! I'm still not sure if it's not better to just merge your commit for master. But I'll leave that up to you.

In other case I would also prefer to make clean up only in master, but you already found few weird related problems.
It should be easer to fix them uniformly.

@iluuu1994
Copy link
Member

Ok, then let's merge this for PHP 8.2.

@dstogov dstogov merged commit c6b75f9 into php:PHP-8.2 May 6, 2024
8 checks passed
dstogov added a commit that referenced this pull request May 6, 2024
* PHP-8.2:
  Fix prototype for trait methods (#14148)
dstogov added a commit that referenced this pull request May 6, 2024
* PHP-8.3:
  Fix prototype for trait methods (#14148)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants