Skip to content

[DeadCode] Add RemoveNullPropertyInitializationRector to dead-code set#1880

Merged
TomasVotruba merged 1 commit intomasterfrom
relocate
Aug 21, 2019
Merged

[DeadCode] Add RemoveNullPropertyInitializationRector to dead-code set#1880
TomasVotruba merged 1 commit intomasterfrom
relocate

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba commented Aug 21, 2019

(before RemoveDeadInitializationRector)

@TomasVotruba TomasVotruba changed the title [DeadCode] Add RemoveNullPropertyInitializationRector [DeadCode] Add RemoveNullPropertyInitializationRector to dead-code set Aug 21, 2019
@TomasVotruba
Copy link
Copy Markdown
Member Author

Ref #1870

@TomasVotruba TomasVotruba merged commit 9820bec into master Aug 21, 2019
@TomasVotruba TomasVotruba deleted the relocate branch August 21, 2019 16:01
@UFTimmy
Copy link
Copy Markdown
Contributor

UFTimmy commented Apr 29, 2020

Maybe this is the wrong place to ask this, but why are nulls on property declarations considered bad? I know I can remove the rector from applying if I don't like, but I was hoping to get a better understanding of why it's considered bad first.

I don't typically use them, but with PHP 7.4 there is a difference between not initialized and null, so for some properties I do initialize them to null so you don't get the accessing an uninitialized field error.

@TomasVotruba
Copy link
Copy Markdown
Member Author

They're not bad at all.

They're as useful as first line here:

$value = [];
$value = [
  $this->getSome();
];

@TomasVotruba
Copy link
Copy Markdown
Member Author

For typed properties it's a different case, see: https://github.com/rectorphp/rector/blob/master/rules/php74/src/Rector/Property/TypedPropertyRector.php

If they're in conflict and this rule breaks PHP 7.4 code, please open an issue. That's a bug.

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.

2 participants