Php-cs-fixer: Return 'void' instead of 'null'

Created on 22 Jul 2016  路  2Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

Hi guys,

Got issue on my last php-cs-fixer run. On my method, I need to return an object, if that object is not found, it's a null (cause if we are going deeper into the code notion, Object -> pointer -> null if nothing).

As I come from C / C ++ development, it's for me a best practice to handle that way.
But the script rewrite my return null to return..

I'm just asking why this is hardcoded that way ? The type returned is different, it should not touch this.

Thanks :)

kinquestion

Most helpful comment

@SpacePossum Yeah I exaggerated on the "hardcoded" term =D

Alright, thanks for the tips :) Gonna use this now.

All 2 comments

Hi,

It is not hardcoded so you can fix this :)
The reason is that the SF doesn't like return null; until recently since the void type has added to PHP7.1.
To stop PHP-CS-Fixer from replacing return null; with return; don't use the empty_return fixer (called simplified_null_return on master), either by removing in your configuration file (or add -empty_return to the fixers list), or use something like --fixers=-empty_return if you run the app from the command line.

@SpacePossum Yeah I exaggerated on the "hardcoded" term =D

Alright, thanks for the tips :) Gonna use this now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bilge picture Bilge  路  3Comments

vitek-rostislav picture vitek-rostislav  路  3Comments

BackEndTea picture BackEndTea  路  3Comments

amitbisht511 picture amitbisht511  路  3Comments

carusogabriel picture carusogabriel  路  3Comments