getgrav / grav-plugin-sitemap

Grav Sitemap Plugin
https://getgrav.org
MIT License
42 stars 42 forks source link

ParseError syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) #109

Open rodrigogiraoserrao opened 1 year ago

rodrigogiraoserrao commented 1 year ago

After one or two years of having the sitemap work flawlessly, it started crashing. I suspect it may be because of the 4.0.0 update.

The error I get is a ParseError as the title of this issue indicates. It points at this line:

https://github.com/getgrav/grav-plugin-sitemap/blame/8b8a402c238cace69254445863c5541b30fe0a23/classes/SitemapEntry.php#L17

The error reads “syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)” and the stack frames are shown below. What else can I provide?

Stack frames ``` 44 ParseError …/user/plugins/sitemap/classes/SitemapEntry.php17 43 Composer\Autoload\{closure} …/vendor/composer/ClassLoader.php427 42 Composer\Autoload\ClassLoader loadClass [internal]0 41 spl_autoload_call …/user/plugins/sitemap/sitemap.php146 40 Grav\Plugin\SitemapPlugin onPagesInitialized …/vendor/symfony/event-dispatcher/EventDispatcher.php264 39 Symfony\Component\EventDispatcher\EventDispatcher doDispatch …/vendor/symfony/event-dispatcher/EventDispatcher.php239 38 Symfony\Component\EventDispatcher\EventDispatcher callListeners …/vendor/symfony/event-dispatcher/EventDispatcher.php73 37 Symfony\Component\EventDispatcher\EventDispatcher dispatch …/system/src/Grav/Common/Grav.php597 36 Grav\Common\Grav fireEvent …/system/src/Grav/Common/Processors/PagesProcessor.php53 35 Grav\Common\Processors\PagesProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 34 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 33 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/TwigProcessor.php38 32 Grav\Common\Processors\TwigProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 31 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 30 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/AssetsProcessor.php39 29 Grav\Common\Processors\AssetsProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 28 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 27 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/SchedulerProcessor.php40 26 Grav\Common\Processors\SchedulerProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 25 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 24 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/BackupsProcessor.php39 23 Grav\Common\Processors\BackupsProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 22 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 21 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/TasksProcessor.php69 20 Grav\Common\Processors\TasksProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 19 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 18 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/RequestProcessor.php64 17 Grav\Common\Processors\RequestProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 16 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 15 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/ThemesProcessor.php38 14 Grav\Common\Processors\ThemesProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 13 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 12 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/PluginsProcessor.php39 11 Grav\Common\Processors\PluginsProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 10 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 9 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Processors/InitializeProcessor.php130 8 Grav\Common\Processors\InitializeProcessor Grav\Common\Processors\{closure} …/system/src/Grav/Common/Debugger.php546 7 Grav\Common\Debugger profile …/system/src/Grav/Common/Processors/InitializeProcessor.php131 6 Grav\Common\Processors\InitializeProcessor process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 5 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 4 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Middlewares/MultipartRequestSupport.php40 3 Grav\Framework\RequestHandler\Middlewares\MultipartRequestSupport process …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php50 2 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php62 1 Grav\Framework\RequestHandler\RequestHandler handle …/system/src/Grav/Common/Grav.php312 0 Grav\Common\Grav process …/index.php47 ```
utagawal commented 1 year ago

Hello,

same kind of issue when reching the sitemap.xml page with plugin version 5.0.0 image

Here is the log :

[2023-10-13 08:27:21] grav.CRITICAL: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) - Trace: #0 ./htdocs/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/srv/d_utagawav...') #1 [internal function]: Composer\Autoload\ClassLoader->loadClass('Grav\\Plugin\\Sit...') #2 ./htdocs/user/plugins/sitemap/sitemap.php(159): spl_autoload_call('Grav\\Plugin\\Sit...') #3 ./htdocs/vendor/symfony/event-dispatcher/EventDispatcher.php(264): Grav\Plugin\SitemapPlugin->onPagesInitialized(Object(RocketTheme\Toolbox\Event\Event), 'onPagesInitiali...', Object(Symfony\Component\EventDispatcher\EventDispatcher)) #4 ./htdocs/vendor/symfony/event-dispatcher/EventDispatcher.php(239): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'onPagesInitiali...', Object(RocketTheme\Toolbox\Event\Event)) #5 ./htdocs/vendor/symfony/event-dispatcher/EventDispatcher.php(73): Symfony\Component\EventDispatcher\EventDispatcher->callListeners(Array, 'onPagesInitiali...', Object(RocketTheme\Toolbox\Event\Event)) #6 ./htdocs/system/src/Grav/Common/Grav.php(597): Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object(RocketTheme\Toolbox\Event\Event), 'onPagesInitiali...') #7 ./htdocs/system/src/Grav/Common/Processors/PagesProcessor.php(53): Grav\Common\Grav->fireEvent('onPagesInitiali...', Object(RocketTheme\Toolbox\Event\Event)) #8 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\PagesProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #9 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #10 ./htdocs/system/src/Grav/Common/Processors/TwigProcessor.php(38): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #11 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\TwigProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #12 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #13 ./htdocs/system/src/Grav/Common/Processors/AssetsProcessor.php(39): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #14 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\AssetsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #15 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #16 ./htdocs/system/src/Grav/Common/Processors/SchedulerProcessor.php(40): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #17 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\SchedulerProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #18 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #19 ./htdocs/system/src/Grav/Common/Processors/BackupsProcessor.php(39): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #20 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\BackupsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #21 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #22 ./htdocs/system/src/Grav/Common/Processors/TasksProcessor.php(69): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #23 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\TasksProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #24 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #25 ./htdocs/system/src/Grav/Common/Processors/RequestProcessor.php(64): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #26 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\RequestProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #27 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #28 ./htdocs/system/src/Grav/Common/Processors/ThemesProcessor.php(38): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #29 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\ThemesProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #30 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #31 ./htdocs/system/src/Grav/Common/Processors/PluginsProcessor.php(39): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #32 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\PluginsProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #33 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #34 ./htdocs/system/src/Grav/Common/Processors/InitializeProcessor.php(130): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #35 ./htdocs/system/src/Grav/Common/Debugger.php(546): Grav\Common\Processors\InitializeProcessor::Grav\Common\Processors\{closure}() #36 ./htdocs/system/src/Grav/Common/Processors/InitializeProcessor.php(131): Grav\Common\Debugger->profile(Object(Closure)) #37 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Common\Processors\InitializeProcessor->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #38 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #39 ./htdocs/system/src/Grav/Framework/RequestHandler/Middlewares/MultipartRequestSupport.php(40): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #40 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(50): Grav\Framework\RequestHandler\Middlewares\MultipartRequestSupport->process(Object(Nyholm\Psr7\ServerRequest), Object(Grav\Framework\RequestHandler\RequestHandler)) #41 ./htdocs/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php(62): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #42 ./htdocs/system/src/Grav/Common/Grav.php(312): Grav\Framework\RequestHandler\RequestHandler->handle(Object(Nyholm\Psr7\ServerRequest)) #43 ./htdocs/index.php(47): Grav\Common\Grav->process() #44 {main} [] []

rodrigogiraoserrao commented 1 year ago

@rhukster I still get this error on 5.0.0 I don't know PHP but I'll happily try to dig into this if you provide some pointers.

Thanks for your help.

rodrigogiraoserrao commented 1 year ago

I replaced

https://github.com/getgrav/grav-plugin-sitemap/blob/8b8a402c238cace69254445863c5541b30fe0a23/classes/SitemapEntry.php#L17-L20

with

    public $timestamp;
    public $rawroute;
    public $longdate;
    public $shortdate;

And now it seems to work.

Did some Googling, found out that the type hints you're using require PHP 7.4 but Grav only requires PHP 7.3.6. This plugin does not specify it requires PHP 7.4+, so I'll make a PR to remove the type hints.