2
What is the purpose of declaring functions initiated with underline?
Eventually I wonder why this.
For example:
protected function _exemplo() {}
It is not enough to declare so?
protected function exemplo() {}
Have some other specific reason to declare the function started by underline, when the statement itself already uses the visibility limiter protected
?
Bonus: If there is another reason, this is restricted to methods only or to properties?
Example (something like that, I just thought):
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 magical method, but it is not!
Example of use in cakephp 2.5 method:
protected function _findAll($state, $query, $results = array()) {
if ($state === 'before') {
return $query;
}
return $results;
}
can you link to this code ? (Github)
– gpupo