声明变量时开头没有 var 符号?
我看到类声明 var _hello_kitty = array(); 为什么他们不使用 $?我试图将其设为 public static $_hello_kitty = array(); ,但如果不添加 $ ,它就无法工作。
现在,当我添加 $
时,通过 _hello_kitty
引用它的其他函数将停止工作。
编辑:哎呀是我的错,我以某种方式从那里删除了 $,我循环了原始文件及其在那里。但它仍然引用 $this->_tpl_vars[$tpl_var] = &$value
没有 $,我
现在 不能使用 self::_tpl_vars[$tpl_var];
我确实使用了 self::$_tpl_vars[$tpl_var];但现在出现错误 array_merge() [function.array-merge]: Argument #1 is not an array i
I have seen class that states var _hello_kitty = array();
why they dont use $? i tried to make it public
and static
and it does not work without adding $
i.e. public static $_hello_kitty = array();
now when i do add $
other functions who reference it by _hello_kitty
stop working.
EDIT: OOOPS was my bad i somehow removed $ from there, i looped up original file and its there. but its still referencing like $this->_tpl_vars[$tpl_var] = &$value
without $ and i cannot use self::_tpl_vars[$tpl_var];
now i did use self::$_tpl_vars[$tpl_var]; but now error comes up array_merge() [function.array-merge]: Argument #1 is not an array i
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在使用 smarty,看起来您正在使用类变量的 PHP 4 表示法:
它的 PHP 5 表示法是:
但您不需要更改代码,因为 PHP 是向后兼容的。只需将其保留原样,以提醒您事情会发生变化,并且对于您自己的代码,您不会使用
var
。如果您实际上需要更改代码,因为它破坏了(而不是您破坏代码因为您想要更改它),您会很早就注意到。
You're using smarty and it looks like you're using the PHP 4 notation of class variables:
The PHP 5 representation of it is:
But you don't need to change the code because PHP is backwards compatible. Just leave it as is as a reminder that things change and for your own code you won't make use of
var
.In case you will actually need to change the code because it breaks (and not you break the code because you want to change it), you will notice early enough.
这就是 PHP 类属性的语法的工作原理。
您可以使用美元符号定义属性,例如
当从类实例(即对象)引用它们时,您可以省略美元符号,例如
更新
静态属性使用
static
关键字声明,然后引用他们喜欢这样
That's how the syntax for PHP class properties works.
You define the property with the dollar-sign, eg
When referencing them from a class instance (ie object), you omit the dollar-sign, eg
Update
Static properties are declared using the
static
keywordYou then reference them like so
在 PHP 中,变量以美元符号为前缀,这是编程语言的 sigil 。这是计算中的一个重要概念,也是 PHP 识别变量的唯一方法。
来自wikipedia(永远不会说谎):
就是这样。
In PHP, variables are prefixed with the dollar sign, which is the programming language's sigil. This is an important concept in computing, and it's the only way PHP is able to identify variables.
From wikipedia (which never, ever lies):
and that's it.