开发者

What is wrong with this php line?

var $foo = array('foo' => $bar);开发者_如何学运维

I am getting an UNEXPECTED T_VARIABLE error. I can't use variables when creating arrays?

This declaration is inside a class, and I am running PHP v5.3.2

When removing the var, I get another error Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION

Thanks


var is not PHP syntax... A simple

$foo = array('foo' => $bar);

would suffice.


The keyword var is only used when declaring variables (i.e. instance variables) in classes, but even that is PHP4 syntax and is currently deprecated. This will do what you want:

$foo = array('foo' => $bar);


try:

$foo = array('foo' => $bar);

See this question for why you are having trouble: What does PHP keyword 'var' do?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜