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 (ie 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?

链接地址: http://www.djcxy.com/p/96570.html

上一篇: 将PHP img src放入字符串中

下一篇: 这个PHP行有什么问题?