为什么 PHP 4.4.9 会抛出“解析错误:语法错误,意外的 T_STATIC"? [英] Why PHP 4.4.9 throws 'Parse error: syntax error, unexpected T_STATIC'?

查看:33
本文介绍了为什么 PHP 4.4.9 会抛出“解析错误:语法错误,意外的 T_STATIC"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚意识到,当 static 关键字添加到 PHP 4 时,Google 教授无法提供我可以找到的特定页面.尽管遵循 php 4 的更改日志 我可以看到它从 4.0.6 版(或之前)开始可用,但为什么会抛出:

I just realized the professor Google is unable to present a specific page where I can find out, when static keyword added to PHP 4. Though following the change log for php 4 I can see that it was available since Version 4.0.6 (or before) but why does it throws:

解析错误:语法错误,意外的 T_STATIC,在 {FILE_PATH+LINE#} 中需要 T_OLD_FUNCTION 或 T_FUNCTION 或 T_VAR 或 '}'

Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in {FILE_PATH+LINE#}

简单代码如下:

class myClass
{
    static $_debug = true;
}

或者这个类变量的赋值是在早期版本的 PHP 中引入的?

Or this assignment of class-variable was introduced in earlier versions of PHP?

推荐答案

我很确定静态类变量对于 PHP5 来说是新的,所以不能在 PHP4 中使用.

I'm pretty sure static class variables are new to PHP5, so can't be used in PHP4.

事情是这样的:PHP4 可以在函数中使用static关键字,而不是在类中.static 的唯一 PHP4 用法是这样的:

Here's the deal: PHP4 can use the static keyword in functions, not classes. The only PHP4 usage of static was like this:

function howManyTimes() {
    static $count = 0;
    echo "Function has been called $count times.";
    $count++;
}

该变量永远绑定到函数的作用域.这就是 PHP4 解释 static 的方式.您尝试使用的 PHP5 解释在您当前的 PHP 版本中不可用.对不起!

That variable is bound to the function's scope forever. That's how PHP4 interprets static. The PHP5 interpretation you are trying to use is not available in your current PHP version. Sorry!

这篇关于为什么 PHP 4.4.9 会抛出“解析错误:语法错误,意外的 T_STATIC"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆