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

Closed
opened 2026-01-22 12:46:06 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 23, 2010).

Originally assigned to: @guilhermeblanco on GitHub.

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->"
Originally created by @doctrinebot on GitHub (Apr 23, 2010). Originally assigned to: @guilhermeblanco on GitHub. 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->" ```
admin added the ImprovementBC Break labels 2026-01-22 12:46:06 +01:00
admin closed this issue 2026-01-22 12:46:06 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 27, 2010):

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 commented on GitHub (Apr 27, 2010): 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?
Author
Owner

@doctrinebot commented on GitHub (Apr 27, 2010):

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 commented on GitHub (Apr 27, 2010): 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).
Author
Owner

@doctrinebot commented on GitHub (Apr 27, 2010):

Comment created by romanb:

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

@doctrinebot commented on GitHub (Apr 27, 2010): Comment created by romanb: Leaving the prefixes on the repository class only is also an option... but I dont think thats necessary.
Author
Owner

@doctrinebot commented on GitHub (Apr 27, 2010):

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 commented on GitHub (Apr 27, 2010): 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
Author
Owner

@doctrinebot commented on GitHub (Apr 27, 2010):

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 commented on GitHub (Apr 27, 2010): 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.
Author
Owner

@doctrinebot commented on GitHub (Apr 27, 2010):

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 commented on GitHub (Apr 27, 2010): 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 :)
Author
Owner

@doctrinebot commented on GitHub (Nov 19, 2010):

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 commented on GitHub (Nov 19, 2010): 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.
Author
Owner

@doctrinebot commented on GitHub (Apr 16, 2014):

Comment created by @guilhermeblanco:

Moving to 3.0 as this can potentially create BC breaks

@doctrinebot commented on GitHub (Apr 16, 2014): Comment created by @guilhermeblanco: Moving to 3.0 as this can potentially create BC breaks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#666