twigphp / Twig

Twig, the flexible, fast, and secure template language for PHP
https://twig.symfony.com/
BSD 3-Clause "New" or "Revised" License
8.17k stars 1.25k forks source link

strange failure in twig core.php #2405

Closed spotstat closed 7 years ago

spotstat commented 7 years ago

I am an inexperienced developer who is having a lot of trouble understanding the Twig installation instructions, so please be patient if I have got something wrong here. My initialization code is: require_once "vendor/autoload.php"; $loader = new Twig_Loader_Filesystem('resources/templates'); $twig = new Twig_Environment($loader, array('cache' => 'resources/cache',)); It results in a server error and the problem is in line 1552 of core.php. The problem is identified as "unexpected '.'" (an unexpected period).

quote: ------------------------------------------------- Internal Server Error

Fatal error: syntax error, unexpected '.'

[vendor/twig/twig/lib/Twig/Extension/Core.php:1552] unquote -------------------------------------------------

Line 1552 is in this code block: try { $ret = $object->$method(...$arguments); // this is line 1552 } catch (BadMethodCallException $e) { if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) { return; } throw $e; } If I remove all three of the periods [(...$arguments) becomes just plain ($arguments)] the error goes away. As I said, I'm inexperienced. The presence of those three periods is no PHP I have ever seen before, but I accept that I could be wrong and the error may actually be elsewhere. But if this is the error, it is apparently an editing oversight and should be corrected. If I'm wrong, could someone please point me to what might be the real cause of my server error. Much appreciated.

SpacePossum commented 7 years ago

Hi, Thanks for your report! To help you further can you please tell us what Twig version (pretty sure it is 2.x but please provide the version :) ) and what PHP version (should be 7.0 or higher) you use. This might help us to help you.

spotstat commented 7 years ago

PHP 7.1.2, Twig 2.x (I'm unsure how to get the twig version, but it's definitely 2.x because that's what I told Composer to install for me this morning.)

spotstat commented 7 years ago

It's Twig 2.1.0, installed this morning.

fabpot commented 7 years ago

Looks like it's not PHP 7. Do you have several PHP installations perhaps? In any case, you should seek help on StackOverflow as more people will be able to help.

HongPong commented 7 years ago

There may be a fix to similar issue here https://github.com/slimphp/Twig-View/issues/77 having to do with how twig packages are designated, in some cases.

stof commented 7 years ago

There is no issue with how Twig packages are designated. The problem in the in the slimphp issue is a misunderstanding of how composer works regarding compatibility with PHP versions when selecting dependencies.