Unexpected character in input: '\' (ASCII=92) state=1
Asked Answered
G

8

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
Gorge answered 17/6, 2013 at 20:27 Comment(12)
@Jessica - 34 actually. ;-)Noggin
I added lines before and after the line 34Gorge
@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.Noggin
@Fred He showed us line 34, I asked to see line 33.Hardesty
@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.Gorge
@Gorge Could be an php safe mode issue. (if it's set to ON). Try setting it to OFF and see if that works.Noggin
@Hardesty Always good to know what's before, for sure.Noggin
@Gorge So, any luck? And, have you looked into my php safe mode comment?Noggin
@Fred Yes, thank you. I will look into it, I am waiting for his reply. I want him to send show me the file with phpinfo(), then I will try with safe mode if the version is greater than 5.3.Gorge
@Gorge Ok, I hope it works out for the best, cheers. Keep us postedNoggin
@Gorge And now, have you looked into php safe mode? Under Configure Command using <?php phpinfo(); ?>, did you or he see enable-safe-mode=yes or enable-safe-mode=no?. As well as under Directive safe_mode Off - Off (local and master values).Noggin
Says his hosting provider checked that the safe mode is Off.Gorge
S
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.

Stoppage answered 17/6, 2013 at 20:39 Comment(3)
5.3 does support namespaces, you probably meant 5.2 and belowQualifier
Factual inaccuracies make the answer not-very-useful, even if they're little brain farts. +1 for fixing it.Qualifier
@Stoppage , I currently have php 5.1. Is there any solution? for a version of php 5.1?Hurst
Q
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.

Qualifier answered 17/6, 2013 at 20:39 Comment(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.Gorge
G
2

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

Guardi answered 25/6, 2015 at 17:35 Comment(0)
U
1

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

Unsnap answered 17/6, 2013 at 20:41 Comment(0)
U
1
<FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|php55|php56|phtml|phps)$">

 AddHandler x-httpd-php53 .php

</FilesMatch>

in .htaccess

Unwept answered 27/10, 2014 at 21:58 Comment(0)
R
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();"); 
}
Rigamarole answered 29/7, 2016 at 0:0 Comment(0)
D
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.
Dumb answered 31/8, 2016 at 0:57 Comment(1)
actully i was looking for this thanks mate you explained very well (y)Typist
M
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.

Medicaid answered 26/3, 2023 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.