Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grav 1.6x and PHP 7.3.1 unexpected Twig error - Twig extension called containsFilter #2460

Closed
paulhibbitts opened this issue Apr 17, 2019 · 6 comments

Comments

@paulhibbitts
Copy link

paulhibbitts commented Apr 17, 2019

Hello,

I've just started getting an unexpected error in Twig which has been working fine until Grav 1.6x and PHP 7.31. The same Twig has been working fine on PHP 7.2 and lower.

Screenshot:
2019-04-17_09-00-31

Grav log file contents (Twig extension called containsFilte seems to trigger the error):
[2019-04-17 09:11:35] grav.CRITICAL: An exception has been thrown during the rendering of a template ("strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior"). - Trace: #0 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/cache/twig/00/00a737342fd262f0628e819ee8fcf9bf46e53a3745cf575954251ffb7f324ae3.php(130): Twig\Template->displayBlock('content', Array, Array) #1 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Template.php(427): __TwigTemplate_4ae23fc7a0730d52940ed9ff3d39163e61fa6e5a67bd5646b918949c28e77d88->doDisplay(Array, Array) #2 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Template.php(398): Twig\Template->displayWithErrorHandling(Array, Array) #3 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/cache/twig/94/94c42a475eb428462f1e099e274edb855abb00ce7495bac86f0a585a987fcb7e.php(245): Twig\Template->display(Array, Array) #4 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Template.php(427): __TwigTemplate_e402550e6896cfb5902a548b96ea65e08a2e2f291e5ae47bcbfc4fd059ac258e___1877705159->doDisplay(Array, Array) #5 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Template.php(398): Twig\Template->displayWithErrorHandling(Array, Array) #6 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/cache/twig/94/94c42a475eb428462f1e099e274edb855abb00ce7495bac86f0a585a987fcb7e.php(30): Twig\Template->display(Array) #7 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Template.php(427): __TwigTemplate_e402550e6896cfb5902a548b96ea65e08a2e2f291e5ae47bcbfc4fd059ac258e->doDisplay(Array, Array) #8 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Template.php(398): Twig\Template->displayWithErrorHandling(Array, Array) #9 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Template.php(406): Twig\Template->display(Array) #10 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/TemplateWrapper.php(47): Twig\Template->render(Array, Array) #11 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/twig/twig/src/Environment.php(385): Twig\TemplateWrapper->render(Array) #12 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Twig/Twig.php(388): Twig\Environment->render('pagerssfeeds.ht...', Array) #13 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Service/OutputServiceProvider.php(28): Grav\Common\Twig\Twig->processSite('html') #14 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/vendor/pimple/pimple/src/Pimple/Container.php(118): Grav\Common\Service\OutputServiceProvider->Grav\Common\Service{closure}(Object(Grav\Common\Grav)) #15 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/RenderProcessor.php(28): Pimple\Container->offsetGet('output') #16 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\RenderProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #17 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #18 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/DebuggerAssetsProcessor.php(28): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #19 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\DebuggerAssetsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #20 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #21 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/PagesProcessor.php(69): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #22 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\PagesProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #23 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #24 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/TwigProcessor.php(27): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #25 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\TwigProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #26 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #27 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/AssetsProcessor.php(28): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #28 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\AssetsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #29 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #30 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/SchedulerProcessor.php(29): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #31 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\SchedulerProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #32 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #33 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/BackupsProcessor.php(28): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #34 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\BackupsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #35 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #36 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/TasksProcessor.php(59): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #37 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\TasksProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #38 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #39 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/RequestProcessor.php(49): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #40 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\RequestProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #41 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #42 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/ThemesProcessor.php(27): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #43 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\ThemesProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #44 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #45 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/PluginsProcessor.php(30): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #46 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\PluginsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #47 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #48 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/InitializeProcessor.php(78): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #49 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\InitializeProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #50 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #51 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/DebuggerProcessor.php(27): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #52 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\DebuggerProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #53 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #54 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/ErrorsProcessor.php(27): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #55 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\ErrorsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #56 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #57 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/LoggerProcessor.php(48): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #58 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\LoggerProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #59 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #60 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Processors/ConfigurationProcessor.php(28): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #61 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(45): Grav\Common\Processors\ConfigurationProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #62 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(57): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #63 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/system/src/Grav/Common/Grav.php(249): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #64 /Users/paulhibbitts/Documents/My Files/GitHub/cpt-363-2018-example-course-hub/index.php(53): Grav\Common\Grav->process() #65 {main} [] []

Thanks very much,
Paul

@rhukster
Copy link
Member

Try changing the containsFilter() function in TwigExtension.php to:

    public function containsFilter($haystack, $needle)
    {
        return (strpos($haystack, (string)$needle) !== false);
    }

@paulhibbitts
Copy link
Author

thanks very much @rhukster , but now I get this error:
2019-04-17_10-15-23

@rhukster
Copy link
Member

Rather than checking if .rss_text_filter is defined, you might want to check if .rss_text_filter is not empty.

In PHP 7.3 the needle has to be a non-empty string

@rhukster
Copy link
Member

also i put a check in the filter:

    public function containsFilter($haystack, $needle)
    {
        if (empty($needle)) {
            return $haystack;
        }

        return (strpos($haystack, (string) $needle) !== false);
    }

@paulhibbitts
Copy link
Author

Ah! That added check now works with no change in the theme code, thank you🙂 I will also make this change on my PHP 7.2 server as a test.

@paulhibbitts
Copy link
Author

Ok @rhukster , that fix was a-ok on PHP 7.2 too👍Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants