为什么Magento中的局部变量具有下划线前缀? [英] Why do local variables in Magento have an underscore prefix?

查看:69
本文介绍了为什么Magento中的局部变量具有下划线前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为对的后续行动>一个更早的问题我想知道是否有人知道为什么Magento模板都用下划线声明其变量.模板是.phtml文件include-从Mage_Core_Block_Template::fetchView()开始的文件,它们的局部变量在函数结尾处被丢弃,并且永远不会成为全局变量.

As a follow up to an earlier question I wonder if anyone knows why Magento templates all declare their variables with an underscore. Templates are .phtml files include-ed from Mage_Core_Block_Template::fetchView(), their local variables are disposed of by the end of the function and never become global.

那么下划线的意义是什么?

So what's the point of an underscore?

推荐答案

我认为这是要尊重ZF的命名约定:

I think it's to respect ZF's naming convention:

http: //framework.zend.com/manual/zh-CN/coding-standard.naming-conventions.html#coding-standard.naming-conventions.variables

对于使用专用"或受保护"修饰符声明的实例变量,变量名称的第一个字符必须为单个下划线.这是变量名称中下划线的唯一可接受的应用程序.声明为"public"的成员变量绝不能以下划线开头.

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.

这篇关于为什么Magento中的局部变量具有下划线前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆