pug-php / pug

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

PHP 7.4 with Pug 2.7.5 minor correction #232

Closed dadajuice closed 4 years ago

dadajuice commented 4 years ago

Hello,

I recently updated PHP to 7.4 for one of my project which runs on Pug 2.7.5 and everything seems to work fine except a minor thing. It triggers the following warning:

Warning: include() [function.include0]: Jade\Stream\Template::stream_set_option is not implemented! in /var/www/quickloc/vendor/pug-php/pug/src/Jade/Jade.php on line 166

Once the page is cached, the warning no longer appears.

Looking at the code I tracked down the origin of the problem which is, I think, in Template.php class (/Jade/Stream/Template.php). It seems this class is used as a "streamWrapper" and maybe PHP 7.4 is now enforcing all interface methods to be implemented and its missing the stream_set_option method as stated in the warning.

So, as a test, I just went on and added the method (based on the PHP.net documentation https://www.php.net/manual/en/streamwrapper.stream-set-option) in the Template.php class simply returning true and it silenced the warning and all went well.

public function stream_set_option (int $option , int $arg1 , int $arg2)
{
    return true;
}

So I don't know if there's more than meets the eye to this apparently easy issue, but if you can simply add this to the build it would be very appreciated :) I know I could just configure my .htaccess to silence warnings, but I'm testing my luck here and see if you have time to check this :)

Thank you very much for your time!

kylekatarnls commented 4 years ago

Yes this method is required in PHP 7.4 and I implemented it in Pug-php 3: https://github.com/phug-php/renderer/commit/5b27d5f9140a97db6338a135cecb73eb8c58bbcd

You can open a pull-request to add it in Pug-php 2 too. But it needs to keep the actual compatibility so don't put the type hints that are not supported in PHP 5.

dadajuice commented 4 years ago

Thank you for your prompt answer! I did a quick PR following your contribute documentation. I sent it into the version-2.next branch as it seems the best and the most logical one for my merge.

Have a nice day!

kylekatarnls commented 4 years ago

Thanks. Version 2.7.6 released.