phpzend-framework3laminas

Laminas MVC upgrade from ZF3 and to PHP8.2


Questions:

  1. Has anyone used Laminas MVC components on PHP8.2 without depracted warnings?
  2. What's the best way to adjust the session settings when migrating.

Issue: using Laminas Migrate and upgrading PHP (7.4 to 8.2) the system throws errors and crashes

"Fatal error: Uncaught Laminas\Session\Exception\InvalidArgumentException: 'session.cookie_lifetime' is not a valid sessions-related ini setting."

The system uses ZF3 MVC and zf-commons/zfc-user but the issue is sessions and other deprecated warnings when upgrading.

The issue is triggered in config/autoload/global.php

return [
// Session configuration.
    'session_config' => [
        // Session cookie will expire in 1 hour.
         'cookie_lifetime' => 60*60*1,
        // Session data will be stored on server maximum for 30 days.
        'gc_maxlifetime'     => 60*60*24*30,
    ],

Code in /Application/Module.php

 public function onBootstrap($e) {
        :
        $sessionManager =  $e->getApplication()->getServiceManager()->get('Zend\Session\SessionManager');
        
        try {
            $sessionManager->start();
            return;
        } catch (\Exception $e) {
            session_unset();
        }

Any tips, pointers or experience with updating Zf2/ZF3 to laminas would be greatly appreciated.


Solution

  • You can remove the code from the onBootstrap method. In laminas the session is started via the AbstractContainer::__construct method. See the link below for the code relevant to that. In laminas Session is autowired via its factories. You can find which ones are being called in the /vendor/laminas/laminas-session/src/ConfigProvider::getDependencyConfig() method. For laminas components that expose support for both Laminas MVC and Mezzio the Module class just proxies to the ConfigProvider class.

    Target laminas component versions that support laminas/laminas-servicemanager 3.x ONLY Laminas MVC does NOT support version 4 of the service manager component

    You can find the migration guide here:

    https://docs.laminas.dev/migration/

    You can find a presentation by Zend here:

    https://www.zend.com/webinars/migrating-zend-framework-laminas

    Location where the session is started

    https://github.com/laminas/laminas-session/blob/80a4108b3f451d0fb3afd1d63fc8a79ead4ddae6/src/AbstractContainer.php#L88

    Since you are trying to upgrade you may want to take a look at the documentation for usage in a laminas-mvc application. It covers all the new options.

    https://docs.laminas.dev/laminas-session/application-integration/usage-in-a-laminas-mvc-application/