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

Return fixer should be risky #1638

Closed
GrahamCampbell opened this issue Dec 29, 2015 · 33 comments
Closed

Return fixer should be risky #1638

GrahamCampbell opened this issue Dec 29, 2015 · 33 comments

Comments

@GrahamCampbell
Copy link
Contributor

The return null; to return; fixer we have needs to be marked as risky as it could break code on php 7.1.

See https://wiki.php.net/rfc/void_return_type.

Also note that the rfc actually changes the definition of void from what we thought it was before. It now strictly means nothing rather than just garbage.

@keradus
Copy link
Member

keradus commented Dec 29, 2015

Could you provide example of risky change as well?

@GrahamCampbell
Copy link
Contributor Author

Just have a fuction marked as return void, and put return null; in it. It's beahviour changes before and after the fixer is run.

@GrahamCampbell
Copy link
Contributor Author

One could argue the code that said return null; was broken already, but who's to say the intention of the original code wasn't to raise a type error.

@GrahamCampbell
Copy link
Contributor Author

We've made a change to the code behaviour, if you see what I mean.

@keradus
Copy link
Member

keradus commented Dec 29, 2015

https://3v4l.org/h0tn2

👍 for change.

Also, it needs to be documented well why it is risky ;)

@GrahamCampbell
Copy link
Contributor Author

3v4l.org

That website doesn't contain the void return type code that's new in php 7.1.

@GrahamCampbell
Copy link
Contributor Author

Only HHVM 3.11 actually gave an output of anything close to what php 7.1.0 will give when it's released. The old version of php 7.1 still thought void was the name of an object.

@keradus
Copy link
Member

keradus commented Dec 29, 2015

I'm ignoring hhvm...

Behavior on php7.1 will be same way, just a bit different Error will be thrown, isn't it?

@GrahamCampbell
Copy link
Contributor Author

Yeh, but in terms of recognising void as a type rather than a class name, it was closer.

@GrahamCampbell
Copy link
Contributor Author

We'll need to wait for the december version of php 7.1 to make it to 3v4l.org

@keradus
Copy link
Member

keradus commented Dec 29, 2015

The problem exists even without change to PHP, as showed on 3v4l.

@GrahamCampbell
Copy link
Contributor Author

https://3v4l.org/1h9P9

@GrahamCampbell
Copy link
Contributor Author

not really - there's still a type error before and after on 7.0

@keradus
Copy link
Member

keradus commented Dec 29, 2015

So let us see what error will be thrown, maybe it will be in same inheritance line.

@stof
Copy link
Contributor

stof commented Dec 31, 2015

Well, actually, this fixer should be removed from the Symfony level if this RFC is accepted in PHP 7, because the rule defined in the Symfony coding standards will become invalid (I already don't like this rule)

@stof
Copy link
Contributor

stof commented Dec 31, 2015

OK, actually, the RFC is already accepted. So we should start a discussion in Symfony instead.

@GrahamCampbell
Copy link
Contributor Author

OK, actually, the RFC is already accepted. So we should start a discussion in Symfony instead.

Doesn't mean another RFC can't be proposed that changes the definition. I preferred the definition that void just meant the returned value shouldn't be used.

@stof
Copy link
Contributor

stof commented Dec 31, 2015

Doesn't mean another RFC can't be proposed that changes the definition. I preferred the definition that void just meant the returned value shouldn't be used.

I actually prefer this definition: if the return value should not be used, why should the code be allowed to return one ?

@stof
Copy link
Contributor

stof commented Dec 31, 2015

The problem exists even without change to PHP, as showed on 3v4l.

this is not true. The existing failure on 3v4l is the PHP 7.0 one, which is checking a class typehint.

The validation of the void return type is done at compile time, not at runtime, so they won't be any exception catched in your 3v4l snippet (the try statement will not even be reached)

@GrahamCampbell
Copy link
Contributor Author

I actually prefer this definition: if the return value should not be used, why should the code be allowed to return one ?

Well, why not?

@GrahamCampbell
Copy link
Contributor Author

It doesn't matter, that's the point.

@SpacePossum
Copy link
Contributor

note; if the void type will happen we need to split the phpdoc_no_empty_return into two fixers as well, since remove null or void are than 2 diff. things.

@keradus
Copy link
Member

keradus commented May 26, 2016

change is finally accepted by Symfony

symfony/symfony#17201
symfony/symfony-docs#6614

TODO:

  1. remove from symfony ruleset phpdoc_no_empty_return and empty_return
  2. split phpdoc_no_empty_return as suggested by @SpacePossum
  3. mark empty_return risky for PHP 7.1 reason

@stof
Copy link
Contributor

stof commented May 26, 2016

mark empty_return risky for PHP 7.1 reason

that's not risky. The risky fixer would be the one doing the opposite change (return null; is forbidden in void function, but return; can always be used).

remove from symfony ruleset phpdoc_no_empty_return

This one should not be removed. We haven't changed our phpdoc CS.

@stof
Copy link
Contributor

stof commented May 26, 2016

I created #1916 to suggest another fixer which would be useful in the Symfony ruleset to replace empty_return to match our updated CS.

@keradus
Copy link
Member

keradus commented May 26, 2016

This one should not be removed. We haven't changed our phpdoc CS.

So we still want to remove both @return null and @return void from PHPDoc ?

@SpacePossum
Copy link
Contributor

So we still want to remove both @return null and @return void from PHPDoc ?

What will be the default return value after 7.1? If it is void (would be an interesting BC but most valid), than we should remove @return void and leave null IMO.

(on a side note; for constructors I still like to remove any @return hint form the PHPDocs)

@keradus
Copy link
Member

keradus commented May 26, 2016

(constructors are totally different case, eg you shouldn't typehint constructor output with: Foo)

keradus added a commit that referenced this issue Jun 7, 2016
…eradus)

This PR was merged into the 1.12 branch.

Discussion
----------

EmptyReturnFixer - move fixer outside of Symfony level

ref #1638

cc @stof

Commits
-------

05ceee5 EmptyReturnFixer - move fixer outside of Symfony level
@rob006
Copy link
Contributor

rob006 commented Jun 12, 2016

What will be the default return value after 7.1? If it is void (would be an interesting BC but most valid), than we should remove @return void and leave null IMO.

void is only pseudo-type, all functions still returns null by default, including void-functions. There is no need to change return; to return null; or return null; to return; or mark this fixer as risky.

@keradus
Copy link
Member

keradus commented Jun 13, 2016

huh?

<?php
function foo(): void {
    return null;
}

PHP 7.1.0alpha1:

Fatal error: A void function must not return a value (did you mean "return;" instead of "return null;"?)

@rob006
Copy link
Contributor

rob006 commented Jun 13, 2016

@keradus Are we still talking about return null; to return; fixer?

@stof
Copy link
Contributor

stof commented Jun 13, 2016

@keradus but the existing fixer is not risky, because it does not add null. It removes it.

@keradus
Copy link
Member

keradus commented Nov 3, 2016

@stof removing it could break the code as well, see #2256

keradus added a commit that referenced this issue Nov 3, 2016
…id (keradus)

This PR was merged into the 1.13 branch.

Discussion
----------

EmptyReturnFixer - it's now risky fixer due to null vs void

ref #1638
https://3v4l.org/7HscE

Commits
-------

fc82a1b EmptyReturnFixer - it's now risky fixer due to null vs void
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

No branches or pull requests

5 participants