3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace AppBundle\Session; use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag, Symfony\Component\EventDispatcher\EventSubscriberInterface, Symfony\Component\HttpKernel\Event\GetResponseEvent, Symfony\Component\HttpKernel\KernelEvents; class LegacySessionHandler implements EventSubscriberInterface { /** * @var string The name of the bag name containing all the brunel values */ const LEGACY_SESSION_BAG_NAME = 'old_app'; /** * {@inheritdoc} */ public static function getSubscribedEvents() { return [ KernelEvents::REQUEST => 'onKernelRequest' ]; } /** * Transfer all the legacy session variables into a session bag, so $_SESSION['user_id'] will be accessible * via $session->getBag('old_app')->get('user_id'). The first bag name is defined as the class constant above * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { /** There might not be a session, in the case of the profiler / wdt (_profiler, _wdt) **/ if (!isset($_SESSION)) { return; } $session = $event->getRequest()->getSession(); /** Only create the old_app bag if it doesn't already exist **/ try { $bag = $session->getBag(self::LEGACY_SESSION_BAG_NAME); } catch (\InvalidArgumentException $e) { $bag = new NamespacedAttributeBag(self::LEGACY_SESSION_BAG_NAME); $bag->setName(self::LEGACY_SESSION_BAG_NAME); $session->registerBag($bag); } foreach ($_SESSION as $key => $value) { /** Symfony prefixes default session vars with an underscore thankfully, so ignore these **/ if (substr($key, 0, 1) === '_' && $key !== self::LEGACY_SESSION_BAG_NAME) { continue; } $bag->set($key, $value); } } }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught Error: Interface "Symfony\Component\EventDispatcher\EventSubscriberInterface" not found in /in/rZqKs:10 Stack trace: #0 {main} thrown in /in/rZqKs on line 10
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Interface 'Symfony\Component\EventDispatcher\EventSubscriberInterface' not found in /in/rZqKs:10 Stack trace: #0 {main} thrown in /in/rZqKs on line 10
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Fatal error: Interface 'Symfony\Component\EventDispatcher\EventSubscriberInterface' not found in /in/rZqKs on line 10
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Interface 'Symfony\Component\EventDispatcher\EventSubscriberInterface' not found in /in/rZqKs on line 11
Process exited with code 255.

preferences:
96.86 ms | 2168 KiB | 4 Q