Skip to content

[VarExporter] Unexpected Cannot indirectly modify readonly property on PHP 8.4 Lazy Object  #59907

Closed
@alexander-schranz

Description

@alexander-schranz

Symfony version(s) affected

7.3-dev, 7.2-dev, (6.4-dev works)

This changes produces the issue: symfony/var-exporter@v7.2.4...7.2

Description

Since 4-5 days in our CI some security related tests are failing. It seems like some changes break the scheb 2fa bundle which wasn't changed in that time. It only happens on current dev version so this bug is not released yet. Testing it locally I found out the error is related only to PHP 8.4 not when 8.3 is used:

Exception: Cannot indirectly modify readonly property Scheb\TwoFactorBundle\Security\TwoFactor\Condition\AuthenticatedTokenCondition::$supportedTokens
Exception-File: /home/runner/work/sulu/sulu/vendor/symfony/var-exporter/Internal/LazyObjectRegistry.php:94

other one:

Error: Cannot indirectly modify readonly property Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Condition\\AuthenticatedTokenCondition::$supportedTokens

\/private\/tmp\/sulu-symfony-reproducer\/vendor\/symfony\/var-exporter\/Internal\/LazyObjectRegistry.php:9
Beautified output:
Error: Cannot indirectly modify readonly property Scheb\TwoFactorBundle\Security\TwoFactor\Condition\AuthenticatedTokenCondition::$supportedTokens  
  in /home/runner/work/sulu/sulu/vendor/symfony/var-exporter/Internal/LazyObjectRegistry.php:94  

Stack trace:  
#0 /home/runner/work/sulu/sulu/vendor/symfony/var-exporter/LazyGhostTrait.php(173)  
#1 /home/runner/work/sulu/sulu/vendor/scheb/2fa-bundle/Security/TwoFactor/Condition/AuthenticatedTokenCondition.php(26)  
#2 /home/runner/work/sulu/sulu/vendor/scheb/2fa-bundle/Security/TwoFactor/Condition/TwoFactorConditionRegistry.php(24)  
#3 /home/runner/work/sulu/sulu/vendor/scheb/2fa-bundle/Security/TwoFactor/Event/AuthenticationTokenListener.php(50)  
#4 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/Debug/WrappedListener.php(115)  
#5 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/EventDispatcher.php(206)  
#6 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/EventDispatcher.php(56)  
#7 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php(122)  
#8 /home/runner/work/sulu/sulu/vendor/symfony/security-http/Authentication/AuthenticatorManager.php(210)  
#9 /home/runner/work/sulu/sulu/vendor/symfony/security-http/Authentication/AuthenticatorManager.php(167)  
#10 /home/runner/work/sulu/sulu/vendor/symfony/security-http/Authentication/AuthenticatorManager.php(149)  
#11 /home/runner/work/sulu/sulu/vendor/symfony/security-http/Firewall/AuthenticatorManagerListener.php(38)  
#12 /home/runner/work/sulu/sulu/vendor/symfony/security-http/Authenticator/Debug/TraceableAuthenticatorManagerListener.php(58)  
#13 /home/runner/work/sulu/sulu/vendor/symfony/security-bundle/Debug/WrappedLazyListener.php(46)  
#14 /home/runner/work/sulu/sulu/vendor/symfony/security-bundle/Security/LazyFirewallContext.php(61)  
#15 /home/runner/work/sulu/sulu/vendor/symfony/security-bundle/Debug/TraceableFirewallListener.php(91)  
#16 /home/runner/work/sulu/sulu/vendor/symfony/security-http/Firewall.php(92)  
#17 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/Debug/WrappedListener.php(115)  
#18 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/EventDispatcher.php(206)  
#19 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/EventDispatcher.php(56)  
#20 /home/runner/work/sulu/sulu/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php(122)  
#21 /home/runner/work/sulu/sulu/vendor/symfony/http-kernel/HttpKernel.php(159)  
#22 /home/runner/work/sulu/sulu/vendor/symfony/http-kernel/HttpKernel.php(76)  
#23 /home/runner/work/sulu/sulu/vendor/symfony/http-kernel/Kernel.php(182)  
#24 /home/runner/work/sulu/sulu/vendor/symfony/http-kernel/HttpKernelBrowser.php(62)  
#25 /home/runner/work/sulu/sulu/vendor/symfony/framework-bundle/KernelBrowser.php(157)  
#26 /home/runner/work/sulu/sulu/vendor/symfony/browser-kit/AbstractBrowser.php(378)  
#27 /home/runner/work/sulu/sulu/src/Sulu/Bundle/TestBundle/Kernel/SuluKernelBrowser.php(57)  
#28 /home/runner/work/sulu/sulu/src/Sulu/Bundle/SecurityBundle/Tests/Functional/AdminControllerTest.php(50)  
#29 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/Framework/TestCase.php(1240)  
#30 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/Framework/TestCase.php(514)  
#31 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/Framework/TestRunner/TestRunner.php(87)  
#32 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/Framework/TestCase.php(361)  
#33 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/Framework/TestSuite.php(369)  
#34 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/Framework/TestSuite.php(369)  
#35 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/Framework/TestSuite.php(369)  
#36 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(64)  
#37 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/src/TextUI/Application.php(210)  
#38 /home/runner/work/sulu/sulu/vendor/phpunit/phpunit/phpunit(104)  
#39 /home/runner/work/sulu/sulu/vendor/bin/phpunit(122)  
#40 {main}  
Raw Output

see also https://github.com/sulu/sulu/actions/runs/13492230675/job/38164758754

      "Error: Cannot indirectly modify readonly property Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Condition\\AuthenticatedTokenCondition::$supportedTokens in \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/var-exporter\/Internal\/LazyObjectRegistry.php:94\nStack trace:\n#0 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/var-exporter\/LazyGhostTrait.php(173): Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Condition\\AuthenticatedTokenCondition::{closure:{closure:Symfony\\Component\\VarExporter\\Internal\\LazyObjectRegistry::getClassAccessors():91}:92}()\n#1 \/home\/runner\/work\/sulu\/sulu\/vendor\/scheb\/2fa-bundle\/Security\/TwoFactor\/Condition\/AuthenticatedTokenCondition.php(26): ContainerQSHLXPS\\AuthenticatedTokenConditionGhost062fca3->__get()\n#2 \/home\/runner\/work\/sulu\/sulu\/vendor\/scheb\/2fa-bundle\/Security\/TwoFactor\/Condition\/TwoFactorConditionRegistry.php(24): Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Condition\\AuthenticatedTokenCondition->shouldPerformTwoFactorAuthentication()\n#3 \/home\/runner\/work\/sulu\/sulu\/vendor\/scheb\/2fa-bundle\/Security\/TwoFactor\/Event\/AuthenticationTokenListener.php(50): Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Condition\\TwoFactorConditionRegistry->shouldPerformTwoFactorAuthentication()\n#4 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/Debug\/WrappedListener.php(115): Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Event\\AuthenticationTokenListener->onAuthenticationTokenCreated()\n#5 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(206): Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener->__invoke()\n#6 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(56): Symfony\\Component\\EventDispatcher\\EventDispatcher->callListeners()\n#7 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/Debug\/TraceableEventDispatcher.php(122): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch()\n#8 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-http\/Authentication\/AuthenticatorManager.php(210): Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher->dispatch()\n#9 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-http\/Authentication\/AuthenticatorManager.php(167): Symfony\\Component\\Security\\Http\\Authentication\\AuthenticatorManager->executeAuthenticator()\n#10 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-http\/Authentication\/AuthenticatorManager.php(149): Symfony\\Component\\Security\\Http\\Authentication\\AuthenticatorManager->executeAuthenticators()\n#11 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-http\/Firewall\/AuthenticatorManagerListener.php(38): Symfony\\Component\\Security\\Http\\Authentication\\AuthenticatorManager->authenticateRequest()\n#12 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-http\/Authenticator\/Debug\/TraceableAuthenticatorManagerListener.php(58): Symfony\\Component\\Security\\Http\\Firewall\\AuthenticatorManagerListener->authenticate()\n#13 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-bundle\/Debug\/WrappedLazyListener.php(46): Symfony\\Component\\Security\\Http\\Authenticator\\Debug\\TraceableAuthenticatorManagerListener->authenticate()\n#14 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-bundle\/Security\/LazyFirewallContext.php(61): Symfony\\Bundle\\SecurityBundle\\Debug\\WrappedLazyListener->authenticate()\n#15 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-bundle\/Debug\/TraceableFirewallListener.php(91): Symfony\\Bundle\\SecurityBundle\\Security\\LazyFirewallContext->__invoke()\n#16 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/security-http\/Firewall.php(92): Symfony\\Bundle\\SecurityBundle\\Debug\\TraceableFirewallListener->callListeners()\n#17 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/Debug\/WrappedListener.php(115): Symfony\\Component\\Security\\Http\\Firewall->onKernelRequest()\n#18 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(206): Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener->__invoke()\n#19 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(56): Symfony\\Component\\EventDispatcher\\EventDispatcher->callListeners()\n#20 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/event-dispatcher\/Debug\/TraceableEventDispatcher.php(122): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch()\n#21 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/http-kernel\/HttpKernel.php(159): Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher->dispatch()\n#22 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/http-kernel\/HttpKernel.php(76): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#23 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/http-kernel\/Kernel.php(182): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#24 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/http-kernel\/HttpKernelBrowser.php(62): Symfony\\Component\\HttpKernel\\Kernel->handle()\n#25 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/framework-bundle\/KernelBrowser.php(157): Symfony\\Component\\HttpKernel\\HttpKernelBrowser->doRequest()\n#26 \/home\/runner\/work\/sulu\/sulu\/vendor\/symfony\/browser-kit\/AbstractBrowser.php(378): Symfony\\Bundle\\FrameworkBundle\\KernelBrowser->doRequest()\n#27 \/home\/runner\/work\/sulu\/sulu\/src\/Sulu\/Bundle\/TestBundle\/Kernel\/SuluKernelBrowser.php(57): Symfony\\Component\\BrowserKit\\AbstractBrowser->request()\n#28 \/home\/runner\/work\/sulu\/sulu\/src\/Sulu\/Bundle\/SecurityBundle\/Tests\/Functional\/AdminControllerTest.php(50): Sulu\\Bundle\\TestBundle\\Kernel\\SuluKernelBrowser->jsonRequest()\n#29 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/Framework\/TestCase.php(1240): Sulu\\Bundle\\SecurityBundle\\Tests\\Functional\\Controller\\AdminControllerTest->testUserMetadataAction()\n#30 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/Framework\/TestCase.php(514): PHPUnit\\Framework\\TestCase->runTest()\n#31 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/Framework\/TestRunner\/TestRunner.php(87): PHPUnit\\Framework\\TestCase->runBare()\n#32 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/Framework\/TestCase.php(361): PHPUnit\\Framework\\TestRunner->run()\n#33 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/Framework\/TestSuite.php(369): PHPUnit\\Framework\\TestCase->run()\n#34 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/Framework\/TestSuite.php(369): PHPUnit\\Framework\\TestSuite->run()\n#35 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/Framework\/TestSuite.php(369): PHPUnit\\Framework\\TestSuite->run()\n#36 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/TextUI\/TestRunner.php(64): PHPUnit\\Framework\\TestSuite->run()\n#37 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/src\/TextUI\/Application.php(210): PHPUnit\\TextUI\\TestRunner->run()\n#38 \/home\/runner\/work\/sulu\/sulu\/vendor\/phpunit\/phpunit\/phpunit(104): PHPUnit\\TextUI\\Application->run()\n#39 \/home\/runner\/work\/sulu\/sulu\/vendor\/bin\/phpunit(122): include('...')\n#40 {main}"

How to reproduce

git clone git@github.com:sulu/sulu.git sulu
cd sulu

php -v # make sure you are on php 8.4

composer config minimum-stability dev
composer update

docker compose up

env DATABASE_URL="mysql://root:ChangeMe@127.0.0.1:3306/sulu?serverVersion=8.0.27&charset=utf8mb4" bin/runtests -i -t SecurityBundle

Most of the functional tests will error which acces 2FA Bundle:

Output Image

Possible Solution

No response

Additional Context

Only on PHP 8.4. Seems like there are some lazy proxy issues with readonly classes?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions