Skip to content

Loading…

DDC-536: Remove the _ prefix from private and protected members #5044

Open
doctrinebot opened this Issue · 8 comments

2 participants

@doctrinebot

Jira issue originally created by user romanb:

The reasoning is simple: The prefix "_" is usually either used for easier distinction of instance variables from other, i.e. local variables, instead of always using "this." (often seen in C#), or it is used to signal that a member is not meant to be accessed from outside of the class when the language does not have visibility modifiers (PHP4).

Since you always have to use "$this->" in PHP5+ when accessing instance members and there are visibility modifiers, the "_" is largely superfluous and just makes the verbose OO code even more verbose.

Maybe the following find/replace steps will do the job almost completely:

"private $_" => "private $"
"protected $_" => "protected $"
"$this->_" => "$this->"
@doctrinebot

Comment created by @beberlei:

i just found a possible BC issue with this.

EntityRepository is allowed to be extended by us, it has several variables that are underscore prefixed. How to proceed in this case?

@doctrinebot

Comment created by romanb:

I know but its not really a problem I think. We should just decide whether we make them private in the first place and provide getters instead (which would have avoided this problem in the first place).

@doctrinebot

Comment created by romanb:

Leaving the prefixes on the repository class only is also an option... but I dont think thats necessary.

@doctrinebot

Comment created by @beberlei:

can we commit getters for Beta 1 then? We could give everyone a period until Beta 2 to fix their code and then make the change.

EntityRepository is the only class that is meant to be userland extendable to my knowledge, so this should be the only problem to adress

@doctrinebot

Comment created by romanb:

Yes, you can add getters and commit right away if you want. Plus adding a note on the upgrade document that direct access of these properties is deprecated.

@doctrinebot

Comment created by romanb:

Persisters will be also extensible some day in userland but they need more polish for that, I've already started with it :)

@doctrinebot

Comment created by johnnypeck:

Is this still planned? Searching the code base finds this is not being implemented. It would be a good idea to implement the change sooner than later if it will be done at all. Also, +1 for the change. It makes complete sense.

@doctrinebot

Comment created by @guilhermeblanco:

Moving to 3.0 as this can potentially create BC breaks

@doctrinebot doctrinebot added this to the 3.0 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.