phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
62 stars 3 forks source link

syntax error, unexpected '??' (T_COALESCE) #37

Closed rodion-k closed 6 years ago

rodion-k commented 6 years ago

Hello,

I encountered an issue with the following code:

- $test=['attributes' => ['class' => 'foo']];

p&attributes($test['attributes'] ?? [])

I expected to get:

<p class="foo"></p>

But I actually get:

syntax error, unexpected '??' (T_COALESCE)
#0 vendor/phug/renderer/src/Phug/Renderer/AbstractAdapter.php(41): Phug\Renderer\Adapter\EvalAdapter->display('<?php $pugModul...', Array)
#1 vendor/phug/util/src/Phug/Util/SandBox.php(38): Phug\Renderer\AbstractAdapter->Phug\Renderer\{closure}()
#2 vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(100): Phug\Util\SandBox->__construct(Object(Closure), NULL)
#3 vendor/phug/renderer/src/Phug/Renderer/AbstractAdapter.php(29): Phug\Renderer->getNewSandBox(Object(Closure))
#4 vendor/phug/renderer/src/Phug/Renderer/AbstractAdapter.php(42): Phug\Renderer\AbstractAdapter->captureBuffer(Object(Closure))
#5 vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(140): Phug\Renderer\AbstractAdapter->render('<?php $pugModul...', Array)
#6 vendor/phug/util/src/Phug/Util/SandBox.php(38): Phug\Renderer->Phug\Renderer\Partial\{closure}()
#7 vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(100): Phug\Util\SandBox->__construct(Object(Closure), NULL)
#8 vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(142): Phug\Renderer->getNewSandBox(Object(Closure))
#9 vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(207): Phug\Renderer->getSandboxCall('<?php $pugModul...', 'render', 'test.pug', NULL, Object(Closure), Array)
#10 vendor/phug/renderer/src/Phug/Renderer.php(137): Phug\Renderer->callAdapter('render', 'test.pug', NULL, Object(Closure), Array)

Error occurred after the update phug/renderer from dev-master 91b84e0 to 0.4.5. Thanks!

kylekatarnls commented 6 years ago

It works fine on https://pug-demo.herokuapp.com/ with both js and php styles.

What version of PHP do you use?

rodion-k commented 6 years ago

PHP 7.1.17

For me it works with these versions: phug/ast 0.1.0
phug/compiler 0.5.19
phug/dependency-injection 1.3.2
phug/event 0.1.1
phug/formatter 0.5.41
phug/lexer 0.5.21
phug/parser 0.5.8
phug/reader 0.2.1
phug/renderer dev-master 91b84e0 Pug (ex-Jade) renderer for PHP, HTML template engine structured by ... phug/util 0.4.15

And gives error with these versions: phug/ast 0.1.0
phug/compiler 0.5.19
phug/dependency-injection 1.3.2
phug/event 0.1.2 Phug events manager (compatible with PSR-14) phug/formatter 0.5.42 Pug (ex-Jade) formatter for PHP, HTML template engine structured by... phug/lexer 0.5.27 Pug (ex-Jade) lexer for PHP, HTML template engine structured by ind... phug/parser 0.5.8
phug/phug dev-master 33f446b Pug (ex-Jade) facade engine for PHP, HTML template engine structure... phug/reader 0.2.1
phug/renderer 0.4.5 Pug (ex-Jade) renderer for PHP, HTML template engine structured by ... phug/util 0.4.15

kylekatarnls commented 6 years ago

Thanks, the exact break happens between phug/lexer 0.5.22 and 0.5.23. I will see the changes.

kylekatarnls commented 6 years ago

Hi, lexer 0.5.28 should fix it. Can you retry with all dependencies as last stable?

rodion-k commented 6 years ago

It works, thanks!