我收到“语法错误,意外的 T_VARIABLE”错误。我不明白我做错了什么?
我收到此错误: “PHP 解析错误:语法错误,/var/www/vhosts/... 第 66 行出现意外的 T_VARIABLE”
这是我的代码:
function combine($charArr, $k) {
$currentsize = sizeof($charArr);
static $combs = array();
static $originalsize = $currentsize; ###### <-- LINE 66 ######
static $firstcall = true;
if ($originalsize >= $k) {
# Get the First Combination
$comb = '';
if ($firstcall) { //if this is first call
for ($i = $originalsize-$k; $i < $originalsize; $i++) {
$comb .= $charArr[$i];
}
$combs[] = $comb; //append the first combo to the output array
$firstcall = false; //we only want to do this during the first iteration
}
....
....
}
知道出了什么问题吗?
I'm getting this error:
"PHP Parse error: syntax error, unexpected T_VARIABLE in /var/www/vhosts/... on line 66"
Here's my code:
function combine($charArr, $k) {
$currentsize = sizeof($charArr);
static $combs = array();
static $originalsize = $currentsize; ###### <-- LINE 66 ######
static $firstcall = true;
if ($originalsize >= $k) {
# Get the First Combination
$comb = '';
if ($firstcall) { //if this is first call
for ($i = $originalsize-$k; $i < $originalsize; $i++) {
$comb .= $charArr[$i];
}
$combs[] = $comb; //append the first combo to the output array
$firstcall = false; //we only want to do this during the first iteration
}
....
....
}
Any idea what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
引用手册(该页面是关于静态属性,但这同样适用于变量):
您正在使用这个:
它是用表达式初始化的——而不是常量。
And here's [the manual's section][2] that says quite the same about static variables :
而且,为了以防万一,这里有关于表达式。
In your case, to avoid that problem, I suppose you could modify your code, so it looks like this :
这样:
Quoting the manual (that page is about static properties, but the same applies for variables) :
You are using this :
Which is initializing with an expression -- and not a constant.
And here's [the manual's section][2] that says quite the same about static variables :
And, just in case, here's about expressions.
In your case, to avoid that problem, I suppose you could modify your code, so it looks like this :
With that :
您不能将变量作为静态变量的默认值传递。相反,请执行以下操作:
You can't pass a variable as the default value of a static variable. Instead, do the following:
引用 php 手册:
To quote the php manual:
来自 php 手册:
From php manual: