Answer the question
In order to leave comments, you need to log in
Properties for getter and setter in PHP?
I read www.yiiframework.com/doc-2.0/guide-concept-propert...
I can't understand, but always the properties with which getters and setters work must begin with "_" ?
And if so, is this an OOP feature in php or a specific framework?
Answer the question
In order to leave comments, you need to log in
I can be wrong, but in my opinion, in the days of php 4, private methods and properties were named with the first character _, for ease of understanding.
Naming properties with an underscore is the wrong way, which for reasons unknown to me is followed by yii2 code-style ( https://github.com/yiisoft/yii2-coding-standards). There it is proposed to use underlining for all private variables.
the name of a variable and property should not reflect its scope, but only the assignment in the current context (method, block, closure, loop, etc.). Everything else is extra knowledge about the context, which makes the variable more "bound".
This is a feature of Yii, related to the fact that getters and setters are called using "magic" methods when accessing an attribute
I can’t understand, but always the properties with which getters and setters work must begin with "_"?It's just poor quality code left over from the days of PHP4.
Property names SHOULD NOT be prefixed with a single underscore to indicate
protected or private visibility.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question