What is the purpose of declaring functions started underline?
Eventually I wonder why.
For example:
protected function _exemplo() {}
Is not that enough to declare?
protected function exemplo() {}
Is there any other specific reason to declare the function started by underline, when the declaration itself already uses the visibility limiter protected
?
Bonus: If there is another reason, is this restricted to methods or properties?
Example (something like that, just crossed my mind):
protected _$var
Examples of use in properties in CakePHP 2.5:
protected $_associationKeys = array(
'belongsTo' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'counterCache'),
'hasOne' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'dependent'),
'hasMany' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'),
'hasAndBelongsToMany' => array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery')
);
/**
* Holds provided/generated association key names and other data for all associations.
*
* @var array
*/
protected $_associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
// @codingStandardsIgnoreStart
/**
* Holds model associations temporarily to allow for dynamic (un)binding.
*
* @var array
*/
public $__backAssociation = array();
In the example above, they used 2 underlins as a magic method, but it is not!
Example of method use in cakephp 2.5:
protected function _findAll($state, $query, $results = array()) {
if ($state === 'before') {
return $query;
}
return $results;
}