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
12
  • @Jessica - 34 actually. ;-) Commented Jun 17, 2013 at 20:36
  • I added lines before and after the line 34
    – bosniamaj
    Commented Jun 17, 2013 at 20:36
  • 1
    @OP I think you may have to show us your full code, if at all possible, unless Jessica can figure this one out without it. Commented Jun 17, 2013 at 20:37
  • @Fred He showed us line 34, I asked to see line 33.
    – Jessica
    Commented Jun 17, 2013 at 20:41
  • @Fred There is not much before that, just checking if there is a variable that says the script is installed, and after this code the html begins.
    – bosniamaj
    Commented Jun 17, 2013 at 20:42

8 Answers 8

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.

3
  • 1
    5.3 does support namespaces, you probably meant 5.2 and below
    – salathe
    Commented Jun 17, 2013 at 20:39
  • 1
    Factual inaccuracies make the answer not-very-useful, even if they're little brain farts. +1 for fixing it.
    – salathe
    Commented Jun 17, 2013 at 20:43
  • @jraede , I currently have php 5.1. Is there any solution? for a version of php 5.1? Commented Dec 14, 2018 at 16:52
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.

1
  • 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
    Commented Jun 17, 2013 at 22:44
2

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

1

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

0
1
<FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|php55|php56|phtml|phps)$">

 AddHandler x-httpd-php53 .php

</FilesMatch>

in .htaccess

0
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.
1
  • actully i was looking for this thanks mate you explained very well (y) Commented Jan 27, 2017 at 6:45
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();"); 
}
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.