为什么 Magento 中的局部变量有一个下划线前缀?
作为之前问题的后续 我想知道是否有人知道为什么 Magento 模板都用下划线声明变量。模板是来自 Mage_Core_Block_Template::fetchView()
的 .phtml 文件 include
-ed,它们的局部变量在函数结束时被释放,并且永远不会成为全局变量。
那么下划线有什么意义呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是为了尊重ZF的命名约定:
http://framework.zend.com/manual/en/coding-standard.naming-conventions.html#coding-standard.naming-conventions.variables
I think it's to respect ZF's naming convention:
http://framework.zend.com/manual/en/coding-standard.naming-conventions.html#coding-standard.naming-conventions.variables
这里没有确定的答案,但我相信这只是 magento 团队内部的编码约定。我相信您通常都知道下划线前缀的历史。这样想并不过分
换句话说,下划线充当警告:
部分问题是 Zend 或其他任何人都没有“官方”建议,在 phtml 文件中应该使用哪种命名约定。
No certain answer here, but I believe it's just an internal magento team coding convention. I'm sure you're aware of the underscore prefix's history in programming in general. It's not too much of a stretch to think that
In other words, the underscore serves as a warning that
Part of the problem is there's no "official" recommendations from Zend, or anyone else, what sort of naming conventions should be used in phtml files.