Undefined constant 'JSON_ERROR_DEPTH'

Hi, I’m trying to update a system that I wrote a long time ago in Zend Framework to run on PHP 8.3. I’ve got it running fine on my development machine (MacOS). When I try and deploy the same body of code on a remote Linux server (which is difficult to debug) I keep getting the same error. I’m wondering whether the problem might be caused by my needing to use composer to (force because of PHP 8.3) install Laminas API tools?

[16-Apr-2025 12:54:43 Europe/Dublin] PHP Fatal error: Uncaught Error: Undefined constant ‘JSON_ERROR_DEPTH’ in /home/s562383/networks/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:27

Stack trace:

#0 /home/s562383/networks/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(613): Laminas\ServiceManager\Factory\InvokableFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), ‘Laminas\ApiTool…’, NULL)

#1 /home/s562383/networks/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(234): Laminas\ServiceManager\ServiceManager->doCreate(‘Laminas\ApiTool…’)

#2 /home/s562383/networks/vendor/laminas-api-tools/api-tools-content-negotiation/src/Module.php(43): Laminas\ServiceManager\ServiceManager->get(‘Laminas\ApiTool…’)

#3 /home/s562383/networks/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): Laminas\ApiTools\ContentNegotiation\Module->onBootstrap(Object(Laminas\Mvc\MvcEvent))

#4 /home/s562383/networks/vendor/laminas/laminas-eventmanager/src/EventManager.php(171): Laminas\EventManager\EventManager-> in /home/s562383/networks/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php on line 27

Add the follow to the use statement section of your file or proceed it with " \ " If its your code causing the error, which after a closer look it appears its not. Laminas API tools have not been updated to support php 8.3 (appears that the last supported version is 8.2) as far as I know. I doubt it will be updated to support 8.3

use const JSON_ERROR_DEPTH;

Also note that laminas api tools have been set to security only. Its no longer recommended to use that package. The suggested replacement is DotKernel although is not a 1-1 replacement and its driven by Mezzio not laminas mvc.

Thank you, Tyrsson. Thank you also for the reminder that Laminas API tools are unsupported for PHP 8.3 - I think that I’m going to have to go back to PHP 8.2 for the time being and concentrate on getting my Laminas system working on that.

[18-Apr-2025 11:15:03 Europe/Dublin] PHP Fatal error: Uncaught Error: Undefined constant ‘JSON_ERROR_DEPTH’ in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:27
Stack trace:
#0 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(615): Laminas\ServiceManager\Factory\InvokableFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), ‘Laminas\ApiTool…’, NULL)
#1 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(234): Laminas\ServiceManager\ServiceManager->doCreate(‘Laminas\ApiTool…’)
#2 /home/s562383/laminas-old/vendor/laminas-api-tools/api-tools-content-negotiation/src/Module.php(43): Laminas\ServiceManager\ServiceManager->get(‘Laminas\ApiTool…’)
#3 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): Laminas\ApiTools\ContentNegotiation\Module->onBootstrap(Object(Laminas\Mvc\MvcEvent))
#4 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(171): Laminas\EventMana in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php on line 27

Added “use const JSON_ERROR_DEPTH;” to /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory

[18-Apr-2025 11:24:30 Europe/Dublin] PHP Fatal error: Uncaught Error: Undefined constant ‘JSON_ERROR_DEPTH’ in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:29
Stack trace:
#0 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(615): Laminas\ServiceManager\Factory\InvokableFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), ‘Laminas\ApiTool…’, NULL)
#1 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(234): Laminas\ServiceManager\ServiceManager->doCreate(‘Laminas\ApiTool…’)
#2 /home/s562383/laminas-old/vendor/laminas-api-tools/api-tools-content-negotiation/src/Module.php(43): Laminas\ServiceManager\ServiceManager->get(‘Laminas\ApiTool…’)
#3 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): Laminas\ApiTools\ContentNegotiation\Module->onBootstrap(Object(Laminas\Mvc\MvcEvent))
#4 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(171): Laminas\EventMana in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php on line 29

It therefore just moved the place the error is being thrown down 2 lines.

I then added “use const \JSON_ERROR_DEPTH;” to /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory

[18-Apr-2025 11:36:24 Europe/Dublin] PHP Fatal error: Uncaught Error: Undefined constant ‘JSON_ERROR_DEPTH’ in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:29
Stack trace:
#0 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(615): Laminas\ServiceManager\Factory\InvokableFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), ‘Laminas\ApiTool…’, NULL)
#1 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(234): Laminas\ServiceManager\ServiceManager->doCreate(‘Laminas\ApiTool…’)
#2 /home/s562383/laminas-old/vendor/laminas-api-tools/api-tools-content-negotiation/src/Module.php(43): Laminas\ServiceManager\ServiceManager->get(‘Laminas\ApiTool…’)
#3 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): Laminas\ApiTools\ContentNegotiation\Module->onBootstrap(Object(Laminas\Mvc\MvcEvent))
#4 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(171): Laminas\EventMana in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php on line 29

I then commented out the new “use const \JSON_ERROR_DEPTH;” in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory and uploaded that. Same error message in the logs.

I then added “use const JSON_ERROR_DEPTH;” to the top of my /public/index.php file. Same error message.

I then thought to go up one directory in the Stack trace and therefore added “use const JSON_ERROR_DEPTH;” to the top of /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php

[18-Apr-2025 11:49:28 Europe/Dublin] PHP Fatal error: Uncaught Error: Undefined constant ‘JSON_ERROR_DEPTH’ in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:29
Stack trace:
#0 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(616): Laminas\ServiceManager\Factory\InvokableFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), ‘Laminas\ApiTool…’, NULL)
#1 /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(235): Laminas\ServiceManager\ServiceManager->doCreate(‘Laminas\ApiTool…’)
#2 /home/s562383/laminas-old/vendor/laminas-api-tools/api-tools-content-negotiation/src/Module.php(43): Laminas\ServiceManager\ServiceManager->get(‘Laminas\ApiTool…’)
#3 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(319): Laminas\ApiTools\ContentNegotiation\Module->onBootstrap(Object(Laminas\Mvc\MvcEvent))
#4 /home/s562383/laminas-old/vendor/laminas/laminas-eventmanager/src/EventManager.php(171): Laminas\EventMana in /home/s562383/laminas-old/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php on line 29

Which file should I be adding the “use const JSON_ERROR_DEPTH;”, please? Should I be trying “use const \JSON_ERROR_DEPTH;” in all the stack trace? I’m terrified of flailing around too much on files in the /vendor subdirs for fear of breaking things even more.

Your actual error is going to be in whatever object the service manager is trying to retrieve an instance of at that point. Api tools is complicating it here I’m sure since it handles so much automated workflow (I’m not real familiar with it, last I tested it was back just after the release of ZF2). So, most productive place to start…? The classes mapped to InvokableFactory by you or API tools for you that could possibly be executed by that request.

I really wished that the $requestedName argument could be returned by that error.