21

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;

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?

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:

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
bosniamaj
  • 838
  • 4
  • 10
  • 17

8 Answers8

40

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.

-- Edit: mixed up the versions. It's 5.2 and below that don't have namespaces, if I'm not mistaken.

jraede
  • 6,846
  • 5
  • 29
  • 32
13

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?

His PHP version is actually < 5.3.0, whether he knows that or not.

See the error occurring on many PHP versions.

Community
  • 1
  • 1
salathe
  • 51,324
  • 12
  • 104
  • 132
  • Well, he is telling me it is 5.3.24. He didn't make a file with `phpinfo()` when I asked him to, but he copied some stats (probably from cpanel or something). I posted his reply as my EDIT 2 in my post. – bosniamaj Jun 17 '13 at 22:44
2

If you get 'unexpected T_STRING' error after your mentioned error, you need to install PHP 5.4+

Mojtaba
  • 4,852
  • 5
  • 21
  • 38
1

Ask him to create a file with phpinfo(). He probably doesn't have PHP version >= 5.3.0.

silkfire
  • 24,585
  • 15
  • 82
  • 105
1
<FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|php55|php56|phtml|phps)$">

 AddHandler x-httpd-php53 .php

</FilesMatch>

in .htaccess

1

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 version and use the eval() function to avoid that lower versions of PHP shoot an error, even on compilation time.

Something like this:

if ( phpversion() > '5.3.0' ){
    include_once('/path/to/Library.php'); 
    eval("Library\Foo::bar();"); 
}
caos30
  • 31
  • 7
1

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

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.
Thiago Cardoso
  • 503
  • 7
  • 13
0

In my case I was running Vagrant with Virtualbox, and there is known bug with Oracle with the sendfile system call, that causes files to be read only partially if it's on the shared folder. Possible fixes include adding to the nginx config

 sendfile off;

But this doesn't always help. In my latest case, just editing the file (add a comment or space), saving it again, and finally restarting php-fpm helped.

PHZ.fi-Pharazon
  • 1,479
  • 14
  • 15