php 输入中出现意外字符:'\' (ASCII=92) state=1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17156251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unexpected character in input: '\' (ASCII=92) state=1
提问by bosniamaj
My client says he is getting this error using my script:
我的客户说他使用我的脚本收到此错误:
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
The line 34 in header.php
is just use \Main\Class;
第 34 行header.php
就是use \Main\Class;
Now, I told him he has to have PHP >= 5.3.0
and he says his PHP version is 5.3.24
现在,我告诉他他必须拥有PHP >= 5.3.0
,他说他的 PHP 版本是5.3.24
What could be the problem?
可能是什么问题呢?
EDIT: The lines before and after
编辑:之前和之后的行
30. // Define absolute path
31. define("ABSPATH", $abs_path);
32. $_SESSION["abs_path"] = ABSPATH;
33.
34. use \CNS\main\CNS;
35. $cns = new CNS();
EDIT 2:
编辑2:
He sent me this:
他给我发了这个:
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
回答by jraede
This happens if you are trying to use namespaces but do not have PHP 5.3. PHP 5.2 and below don't support namespaces and throw this error when they see the backslash.
如果您尝试使用命名空间但没有 PHP 5.3,就会发生这种情况。PHP 5.2 及以下版本不支持命名空间,并在看到反斜杠时抛出此错误。
-- Edit: mixed up the versions. It's 5.2 and below that don't have namespaces, if I'm not mistaken.
- 编辑:混淆版本。如果我没记错的话,5.2 及以下没有命名空间。
回答by salathe
Now, I told him he has to have PHP >= 5.3.0 and he says his PHP version is 5.3.24
What could be the problem?
现在,我告诉他他必须有 PHP >= 5.3.0,他说他的 PHP 版本是 5.3.24
可能是什么问题呢?
His PHP version is actually < 5.3.0, whether he knows that or not.
他的 PHP 版本实际上是 < 5.3.0,不管他是否知道。
回答by Mojtaba
If you get 'unexpected T_STRING' error after your mentioned error, you need to install PHP 5.4+
如果您在提到的错误后收到“意外的 T_STRING”错误,则需要安装 PHP 5.4+
回答by caos30
Like other users say: use of namespaces are only valid for PHP versions greater than 5.3.0 so my solution for be able to include an optional use of a library using namespaces is to check the php versionand use the eval()function to avoid that lower versions of PHP shoot an error, even on compilation time.
就像其他用户说的那样:使用命名空间仅对高于 5.3.0 的 PHP 版本有效,因此我的解决方案是,能够包含使用命名空间的库的可选使用,是检查 php 版本并使用eval()函数来避免即使在编译时,较低版本的 PHP 也会出错。
Something like this:
像这样的东西:
if ( phpversion() > '5.3.0' ){
include_once('/path/to/Library.php');
eval("Library\Foo::bar();");
}
回答by Thiago Cardoso
I ran the same problem, and doing some research I managed to fix it.
In my case, I use PHP7, and what I had to do is edit the file laravel located in ~/.composer/vendor/laravel/installer/
, where the shebang line was #!/usr/bin/env php
I changed to #!/usr/bin/env php7
我遇到了同样的问题,做了一些研究,我设法解决了它。就我而言,我使用 PHP7,我必须做的是编辑位于 中的文件 laravel ~/.composer/vendor/laravel/installer/
,#!/usr/bin/env php
我将 shebang 行更改为#!/usr/bin/env php7
After run again the artisan, I got it working:
再次运行工匠后,我开始工作了:
-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.
回答by silkfire
Ask him to create a file with phpinfo()
. He probably doesn't have PHP version >= 5.3.0.
请他创建一个带有phpinfo()
. 他可能没有 PHP 版本 >= 5.3.0。
回答by Popov Andrey
<FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|php55|php56|phtml|phps)$">
AddHandler x-httpd-php53 .php
</FilesMatch>
in .htaccess
在.htaccess中