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

Open
opened 2026-01-22 12:46:02 +01:00 by admin · 0 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:02 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#665