Skip to content

Fix ReflectionType::__toString() BC break #2136

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

Closed
wants to merge 1 commit into from
Closed

Fix ReflectionType::__toString() BC break #2136

wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Contributor

@nicolas-grekas nicolas-grekas commented Sep 21, 2016

PHP 7.1 has a BC break that is hitting us hard, that is: ReflectionType::__toString() now adds a ? in front of type hints where null is allowed by their default values.
But since zend_bool is really an unsigned char, we have plenty of room to store and forward this semantic subtlety (nullable being set through ?Foo $arg vs Foo $arg = null) so that ReflectionType::__toString() can be accurate again, thus BC.

@@ -3031,7 +3031,7 @@ ZEND_METHOD(reflection_type, __toString)

str = reflection_type_name(param);

if (param->arg_info->allow_null) {
if (param->arg_info->allow_null & 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't you define a constant instead of using a magic number here ?

@jpauli
Copy link
Member

jpauli commented Sep 21, 2016

Anyway, in 7.1 , you'll need to change your code because of the nullable feature being introduced.

  • __toString() should be deprecated, and the new getName() method should be used now.
  • getName() returns the name, with no '?' or things like that.
  • In 7.1 , you should use getName()
  • You may use isNullable() to probe if the parameter is nullable or not

@Ocramius
Copy link
Contributor

You will need to change the code for new features, but old code should still reflect the same.

That's what BC is all about, and I'm kinda sick of explaining it, at this point.

Development of zendframework/zend-code, doctrine/common and ocramius/proxy-manager halted again :-\

@morrisonlevi
Copy link
Contributor

@Ocramius If we keep the BC then zendframework/zend-code, doctrine/common and ocramius/proxy-manager get to keep working but it's basically useless for everyone else.

That's what BC breaks are all about and I'm kinda sick of explaining it, at this point.

@Ocramius
Copy link
Contributor

it's basically useless for everyone else.

still need to see that "everyone else". We discussed it, and it ended up with "it's internal stuff that you can't haz".

@morrisonlevi
Copy link
Contributor

morrisonlevi commented Sep 21, 2016

@Ocramius So you don't respect NDAs or other forms of respecting material that aren't yours?

@Ocramius
Copy link
Contributor

I agree, still, breaking few million projects (dependants) vs breaking your
internal ones, heh.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On Wed, Sep 21, 2016 at 8:52 PM, Levi Morrison notifications@github.com
wrote:

@Ocramius https://github.com/Ocramius So you don't respect NDAs or
other forms of respecting material that isn't yours?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2136 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAJakKeYoBls-Sl7bKMAvxEc_YXId3uGks5qsXz8gaJpZM4KCjQx
.

@morrisonlevi
Copy link
Contributor

If you are writing code generators I hardly think this is the most difficult BC break. In fact, I'm fairly certain you've spent more time fighting the change than it would have been to just make it compatible. You already know what to do if you are on 7.0; if you are on 7.1 just take a different code path with the new API.

Seriously, I offer right now to fix it for you as long as you'll collaborate with me on it (since I'm obviously not as familiar with the projects as you are).

@Ocramius
Copy link
Contributor

I actually worked an entire week to introduce compat with void and
nullable types on just 2 of the 4 libraries I know of, and the test suit
covering those scenarios is not even complete yet.

I already fixed this shit, the point is that this shit shouldn't need
fixing in first place, since it's not a major release.

Oh, and I'm dropping PHP 7.0 support due to the complexity of maintaining
support for both 7.1 and 7.0 (just headaches).

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On Wed, Sep 21, 2016 at 9:01 PM, Levi Morrison notifications@github.com
wrote:

If you are writing code generators I hardly think this is the most
difficult BC break. In fact, I'm fairly certain you've spent more time
fighting the change than it would have been to just make it compatible. You
already know what to do if you are on 7.0; if you are on 7.1 just take a
different code path with the new API.

Seriously, I offer right now to fix it for you as long as you'll
collaborate with me on it (since I'm obviously not as familiar with the
projects as you are).


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2136 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAJakAu_mmhdKjOxgEBXons1KbzxaKLqks5qsX8FgaJpZM4KCjQx
.

@ciaranmcnulty
Copy link

👍 for this - Prophecy is impacted for basically no reason.

We obviously have work to do to support Nullable types but breaking Foo $foo = null for existing codebases is a hard BC break and against the versioning policy.

@nicolas-grekas
Copy link
Contributor Author

Closing in favor of #2137
Please transfer support to this alternative PR :)

@nicolas-grekas nicolas-grekas deleted the fix-reflection-type-bc-break branch September 24, 2016 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants