Why does the Zend framework prepend an underscore here?

前提是你 提交于 2019-12-24 05:17:25

问题


What's the point of having $_comment instead of $comment?

class Default_Model_Guestbook
{
    protected $_comment;
    protected $_created;
    protected $_email;
    protected $_id;
    protected $_mapper;

回答1:


Prefixing protected and private class variables is a common convention in PHP. It makes it easier to distinguish between those that are public and those that are protected or private.




回答2:


Quoted from the Zend Framework Coding Conventions

For instance variables that are declared with the "private" or "protected" modifier, the first character of the variable name must be a single underscore. This is the only acceptable application of an underscore in a variable name. Member variables declared "public" should never start with an underscore.

Following a Code Convention means all developers working on a project share the same coding style. This is supposed to make the code more readable and thus easier to work with and on. When working with ZF, you should stick to these conventions as close as possible.

When working with non-ZF PHP code, you are encouraged to use the PEAR PHP Coding Standard instead. Makes life easier for everyone who has to maintain your code (even yourself).



来源:https://stackoverflow.com/questions/1798916/why-does-the-zend-framework-prepend-an-underscore-here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!