20

我的客户说他使用我的脚本遇到了这个错误:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /path/to//header.php  on line 34
Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in/path/to/header.php  on line 34

第 34 行header.php只是use \Main\Class;

现在,我告诉他他必须拥有PHP >= 5.3.0,他说他的 PHP 版本是5.3.24

可能是什么问题呢?

编辑:之前和之后的行

30. // Define absolute path
31. define("ABSPATH", $abs_path);
32. $_SESSION["abs_path"] = ABSPATH;
33. 
34. use \CNS\main\CNS;
35. $cns = new CNS();

编辑2:

他给我发了这个:

Program     Version
Apache:     2.2.24
CentOS:     CentOS release 6.4 (Final)
cPanel:     11.36.1 (build 8)
Curl:       7.12.1
MySQL       5.5.30
phpMyAdmin  3.5.5
Python:     2.6.6
Program     Version
Perl:       5.8.8
**PHP:        5.3.24**
ionCube Loader:     4.2.2
Zend Optimizer:     3.3.9
Ruby:       1.8.7
Rails:      3.2.8
OpenSSL:    1.0.0-fips
4

7 回答 7

40

如果您尝试使用命名空间但没有 PHP 5.3,则会发生这种情况。PHP 5.2 及更低版本不支持命名空间并在看到反斜杠时抛出此错误。

- 编辑:混合版本。如果我没记错的话,它是 5.2 及以下版本没有命名空间。

于 2013-06-17T20:39:20.843 回答
13

现在,我告诉他他的 PHP >= 5.3.0,他说他的 PHP 版本是 5.3.24

可能是什么问题呢?

他的 PHP 版本实际上是 < 5.3.0,不管他是否知道。

查看许多 PHP 版本上发生的错误

于 2013-06-17T20:39:25.183 回答
2

如果您在提到的错误后收到“意外的 T_STRING”错误,则需要安装 PHP 5.4+

于 2015-06-25T17:35:54.633 回答
1

请他用phpinfo(). 他可能没有 PHP 版本 >= 5.3.0

于 2013-06-17T20:41:22.437 回答
1
<FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|php55|php56|phtml|phps)$">

 AddHandler x-httpd-php53 .php

</FilesMatch>

在.htaccess

于 2014-10-27T21:58:33.007 回答
1

就像其他用户说的那样:使用命名空间仅对大于 5.3.0 的 PHP 版本有效,因此我能够使用命名空间包含可选使用库的解决方案是检查 php 版本并使用eval()函数来避免即使在编译时,较低版本的 PHP 也会出错。

像这样的东西:

if ( phpversion() > '5.3.0' ){
    include_once('/path/to/Library.php'); 
    eval("Library\Foo::bar();"); 
}
于 2016-07-29T00:00:00.713 回答
1

我遇到了同样的问题,做了一些研究,我设法解决了它。在我的情况下,我使用 PHP7,我必须做的是编辑位于的文件 laravel ~/.composer/vendor/laravel/installer/,我将 shebang 行#!/usr/bin/env php更改为#!/usr/bin/env php7

再次运行工匠后,我得到了它的工作:

-bash-3.2$ laravel
Laravel Installer version 1.3.3

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help  Displays help for a command
  list  Lists commands
  new   Create a new Laravel application.
于 2016-08-31T00:57:43.913 回答