pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Fatal Error on Pug PHP Error messages. #196

Closed esiao closed 6 years ago

esiao commented 6 years ago

Hello,

Still a fan of your port of pug to php even more since the latest version which is looking more and more like a perfect port. I do have an issue with the new version and the error messages outputed by Pug PHP. I can't know what's wrong with my code since the dumper does end up in a fatal error. I have to comment everything to find what's breaking the renderer and then fix it. Do you by any chance know what's wrong, here's the PHP error message:

( ! ) Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/sites/*/vendor/symfony/var-dumper/Dumper/HtmlDumper.php on line 59

Call Stack

1 | 0.0000 | 242280 | {main}( ) | .../index.php:0 2 | 0.0066 | 242736 | require( '/var/www/sites//public/wp/wp-blog-header.php' ) | .../index.php:5 3 | 0.7796 | 8100752 | require_once( '/var/www/sites//public/wp/wp-includes/template-loader.php' ) | .../wp-blog-header.php:19 4 | 0.7824 | 8108216 | include( '/var/www/sites//public/app/themes//single.php' ) | .../template-loader.php:74 5 | 0.7829 | 8117048 | Site->render( ) | .../single.php:26 6 | 0.8614 | 9024368 | Pug\Engine\Renderer->renderFile( ) | .../site.php:158 7 | 0.8614 | 9025384 | call_user_func:{/var/www/sites/*/vendor/pug-php/pug/src/Pug/Engine/Renderer.php:106} ( ) | .../Renderer.php:106 8 | 0.8614 | 9025416 | Pug\Engine\Renderer->Pug\Engine{closure}( ) | .../Renderer.php:106 9 | 0.8614 | 9025448 | Pug\Engine\Renderer->renderFileWithPhp( ) | .../Renderer.php:99 10 | 0.8614 | 9025488 | Phug\Renderer->renderFile( ) | .../Renderer.php:35 11 | 0.8614 | 9026184 | Phug\Renderer->callAdapter( ) | .../Renderer.php:138 12 | 4.3148 | 13858496 | Phug\Renderer->handleHtmlEvent( ) | .../AdapterTrait.php:220 13 | 8.0170 | 15046232 | Phug\Renderer->handleError( ) | .../AdapterTrait.php:166 14 | 8.0170 | 15046488 | Phug\Renderer->getDebuggedException( ) | .../DebuggerTrait.php:347 15 | 9.5006 | 15349480 | Phug\Renderer->getRendererException( ) | .../DebuggerTrait.php:230 16 | 9.5029 | 15383496 | Phug\Renderer->getErrorMessage( ) | .../DebuggerTrait.php:181 17 | 9.5030 | 15387016 | Phug\Renderer->getErrorAsHtml( ) | .../DebuggerTrait.php:146 18 | 9.5030 | 15388208 | Phug\Util\SandBox->__construct( ) | .../DebuggerTrait.php:87 19 | 9.5030 | 15405368 | Phug\Renderer->Phug\Renderer\Partial\Debug{closure}( ) | .../SandBox.php:38 20 | 9.5030 | 15405648 | spl_autoload_call ( ) | .../SandBox.php:71 21 | 9.5030 | 15405712 | Composer\Autoload\ClassLoader->loadClass( ) | .../SandBox.php:71 22 | 9.5092 | 15405864 | Composer\Autoload\includeFile( ) | .../ClassLoader.php:301

kylekatarnls commented 6 years ago

It seems you have a too old version of PHP the version you have for symfony/var-dumper does not support.

Confirmed by https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/2546 and https://stackoverflow.com/questions/8522984/type-hinting-default-parameters

I guess you may need a symfony/var-dumper version lower to 4, check with composer what you need: https://packagist.org/packages/symfony/var-dumper#v3.4.11

When you run composer update/install, it should take your PHP version into account, but if you commit and deploy manually (what often happen with Wordpress hosting basic tools), you lose this feature. I think you have ran composer update on your local dev machine using PHP 7.1+, then you uploaded your vendor directory to a machine that run PHP 7.0 or even 5.x.

The best practice is to not commit/upload your vendor directory, but only your source code, composer.json (not composer.lock if you run the project with different PHP versions) then run composer install on each machine.

An other best practice is to work a configuration ISO-prod. If your prod run PHP 5.6, then install PHP 5.6 on your machine (you can install multiple versions of PHP for your different projects).

Last best practice: regularly upgrade to last stable versions. PHP 7.2 is awesome, fast and come with lot of cool stuff, don't stay stuck in old versions, upgrade PHP on your dev machines and hosting.

esiao commented 6 years ago

Hi Kyle, thank you for the quick answer. I was able to pin point the issue, which was effectively linked to the version of PHP used. I'm using PuPHPet for my local environment and even if the cli was saying I had PHP 7.1 installed, PHP 5.6 was used by the machine. I had to destroy and start from anew to fix it. The new debug tool is way better by the way. Thanks again for your help 👍

sweiguny commented 5 years ago

Hello esiao,

how did you find out, that your system used a different version of php? I am afraid, that i am having the same issue.

best regard

kylekatarnls commented 5 years ago

Hi @sweiguny you can check in your PHP code what version you ran:

echo phpversion();

And when you run composer update, you can check the PHP from CLI php -v, in most cases (with standard installation), this is the version composer use to download dependencies and check the requirements.

sweiguny commented 5 years ago

thank you!

i've already found that in the meantime, but didn't find my post from before to update that. :smile: with the following command(s) I got apache to use the correct php version.

sudo a2dismod php7.0
sudo a2enmod php7.2
sudo service apache2 restart