-->

Unexpected character in input: '\\' (ASCII

2019-02-12 04:36发布

问题:

I moved my website from local to a hosting, and something happened to me. I include this config file into my index.php (it's the first thing I do):

<?php
require_once __DIR__.'/../../vendor/autoload.php';

// some other stuff

$app = new Silex\Application();
$app['debug'] = true;

$defaultLocale = 'en';

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => array(
                            __DIR__.'/../views', 
                            __DIR__.'/../views/backend', 
                            __DIR__.'/../views/layouts',
                            __DIR__.'/../views/components',
                            __DIR__.'/../views/backend/components', 
                        ),
));
$app->register(new Nicl\Silex\MarkdownServiceProvider());

But the website complains this way:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /public_html/_inc/config.php on line 7

Parse error: syntax error, unexpected T_STRING in /public_html/_inc/config.php on line 7

Basically, line 7 is $app = new Silex\Application();. I'm using Silex and the server is running PHP 5.2. The vendor folder (which contains all the framework and third parties stuff) is in root (/)

I was wondering it had some problems with autoload, but I don't find what could exactly be or how to test it. Do you find anything strange? Thanks in advance.

回答1:

According to the official documentation, Silex requires PHP 5.3 to provide namespace support.
Try to migrate your server to PHP 5.3 in order to get rid of this error.

Silex is a PHP microframework for PHP 5.3.