Skip to content
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

Fixes PHP bug 66331 #1729

Closed
wants to merge 1 commit into from
Closed

Fixes PHP bug 66331 #1729

wants to merge 1 commit into from

Conversation

mkoppanen
Copy link
Contributor

At the moment userland classes cannot inherit from an extension class that is using ZEND_SEND_PREFER_REF instead of ZEND_SEND_REF.

This bug manifests in for example php-memcached-dev/php-memcached#126

I cannot figure out a good test to write for this issue because it requires an internal class.

@laruence laruence added the Bug label Jan 21, 2016
@nikic
Copy link
Member

nikic commented Jan 21, 2016

I think the current behavior is correct here. A prefer-ref argument cannot be substituted with either a by-val or a by-ref argument while preserving the signature semantics. If it's substituted by a by-val argument, it's no longer possible to pass undefined variables to it. If it's substituted by a by-ref argument, it's no longer possible to pass literals to it. Either way, the signatures are incompatible.

@mkoppanen
Copy link
Contributor Author

Hello,

it seems that it's impossible to inherit and override a method from an internal class with such a signature without receiving a notice. This is problem especially with testing tools such as PHPUnit, which I believe mock all methods.

Is the only recommended solution to remove PREFER_REF signatures?

@nikic
Copy link
Member

nikic commented Jan 25, 2016

@mkoppanen Yes, I think that would be the recommended solution. Alternatively, or rather additionally, it may be worthwhile to start a discussion about allowing to pass a literal null to reference arguments with a null default value. It would make sense that if the argument is optional, you can skip it by passing null. However, that's more of a long-term solution.

@krakjoe
Copy link
Member

krakjoe commented Jan 6, 2017

I think I may have personally provoked this PR, I have vague memories regarding this.

It seems I was wrong, and that we cannot merge this, so I'm closing this PR.

If I'm wrong to do that Nikita will open it again and give us more input ... although it seems open and shut case.

@krakjoe krakjoe closed this Jan 6, 2017
@sodabrew
Copy link
Contributor

sodabrew commented Jan 24, 2017

I just did a close read through of the original php-memcached-dev/php-memcached#126 and I have two takeaways:

The approach that php-memcached ultimately took, with a flag on the get method that changes the return value to an array, works great with the new PHP 7.1 list() / [] array destructuring left hand assignment. So this ended up being a win:

['value' => $val, 'cas' => $cas, 'flags' => $flags] = $memcached->get('key', null, Memcached::GET_EXTENDED);

The ability to pass null into an argument position that expects a reference but has a default of null, seems sane to me. Discussion is probably out of scope for a GitHub issue? What's the PHP way to bring up a subtle language change like that?

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants