Hi all,
I’ve been using MIGX 3.0.0-alpha5 on various sites running PHP 8.x without problems.
I think they’ve all been MODX 3.x sites.
I have an issue with a MODX 2.8.4-pl site on PHP 8.1 where, when I enable a certain TV [which uses getImageList to populate a listbox] on a template - editing a resource which uses that template gives a 500 error — in the error log:
[05-Dec-2022 12:17:05 Europe/London] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /home/lcc/public_html/STAGE1/core/cache/includes/elements/modsnippet/1.include.cache.php:183
Stack trace:
#0 /home/lcc/public_html/STAGE1/core/model/modx/modscript.class.php(76): include()
#1 /home/lcc/public_html/STAGE1/core/model/modx/modparser.class.php(537): modScript->process()
#2 /home/lcc/public_html/STAGE1/core/components/pdotools/model/pdotools/pdoparser.class.php(273): modParser->processTag()
#3 /home/lcc/public_html/STAGE1/core/model/modx/modparser.class.php(251): pdoParser->processTag()
#4 /home/lcc/public_html/STAGE1/core/components/pdotools/model/pdotools/pdoparser.class.php(64): modParser->processElementTags()
#5 /home/lcc/public_html/STAGE1/core/model/modx/modchunk.class.php(116): pdoParser->processElementTags()
#6 /home/lcc/public_html/STAGE1/core/model/modx/modx.class.php(1885): modChunk->process()
#7 /home/lcc/public_html/STAGE1/core/model/modx/modtemplatevar.class.php(793): modX->getChunk()
#8 /home/lcc/public_html/STAGE1/core/model/modx/modtemplatevar.class.php(1223): modTemplateVar->processBindings()
#9 /home/lcc/public_html/STAGE1/core/model/modx/processors/element/tv/renders/mgr/input/listbox-multiple.class.php(22): modTemplateVarInputRender->getInputOptions()
#10 /home/lcc/public_html/STAGE1/core/model/modx/modtemplatevar.class.php(1155): modTemplateVarInputRenderListboxMultiple->process()
#11 /home/lcc/public_html/STAGE1/core/model/modx/modtemplatevar.class.php(1195): modTemplateVarRender->render()
#12 /home/lcc/public_html/STAGE1/core/model/modx/modtemplatevar.class.php(452): modTemplateVarInputRender->render()
#13 /home/lcc/public_html/STAGE1/core/model/modx/modtemplatevar.class.php(396): modTemplateVar->getRender()
#14 /home/lcc/public_html/STAGE1/manager/controllers/default/resource/resource.class.php(335): modTemplateVar->renderInput()
#15 /home/lcc/public_html/STAGE1/manager/controllers/default/resource/update.class.php(168): ResourceManagerController->loadTVs()
#16 /home/lcc/public_html/STAGE1/core/model/modx/modmanagercontroller.class.php(155): ResourceUpdateManagerController->process()
#17 /home/lcc/public_html/STAGE1/core/model/modx/modmanagerresponse.class.php(79): modManagerController->render()
#18 /home/lcc/public_html/STAGE1/core/model/modx/modmanagerrequest.class.php(187): modManagerResponse->outputContent()
#19 /home/lcc/public_html/STAGE1/core/model/modx/modmanagerrequest.class.php(135): modManagerRequest->prepareResponse()
#20 /home/lcc/public_html/STAGE1/manager/index.php(59): modManagerRequest->handleRequest()
#21 {main}
thrown in /home/lcc/public_html/STAGE1/core/cache/includes/elements/modsnippet/1.include.cache.php on line 183
Line 183:
$modx->setPlaceholder($totalVar, count($items));
The same error happens on lines 197 and 218 as well.
Line 197:
$count = count($items);
Line 218:
$count = count($items);
I can work around these errors by wrapping the ($items)
as (array($items))
in the getImageList snippet on those lines.
At least that seems to fix the problem - someone may have a better workaround.
I guess my questions are:
a) has anyone else come across this issue?
b) is that fix OK? and
c) can anyone confirm that this code is not PHP8 compliant? - if so I could open an issue on github.
I’m a bit confused as to why I’ve not seen this error come up before as I’ve had very similar setups in other sites - albeit they’ve been MODX3.
Many thanks as always!