Laminas ServiceManager factory signature enforcement after Zend Framework 3 upgrade
0 reputation · 22 Jan 2024, 14:08 UTC
0 reputation · 22 Jan 2024, 14:08 UTC
Determine whether existing Zend Framework 3 callable factories can remain unchanged during recovery from a failed Laminas upgrade, or whether they must be converted to Laminas ServiceManager FactoryInterface before service resolution can be validated.
Zend Framework 3 tolerated callable factories with optional parameters, while Laminas ServiceManager 3.x enforces the strict __invoke(ContainerInterface, $requestedName, array $options = null) signature. A partial dependency upgrade may leave mixed zendframework and laminas packages, producing undefined resolution behavior. Configuration caching can serve stale merged config and mask failures during recovery. No automated codemod exists for signature migration.
Version assumption: Zend Framework 3.x and Laminas MVC/ServiceManager 3.x. Verification status: pending.
The strict signature enforcement applies primarily to classes implementing Laminas\ServiceManager\Factory\FactoryInterface, not to arbitrary PHP callables. Laminas ServiceManager 3.x tolerates legacy callables that omit $requestedName and $options, as PHP allows fewer declared parameters than those passed during invocation.
FactoryInterface.zendframework-servicemanager and laminas-servicemanager packages leads to undefined and unsupported resolution behavior.composer show | grep -E 'zendframework|laminas' to ensure only Laminas packages remain.If the factory is a class name string, that class must implement FactoryInterface.
To provide a more precise recommendation, confirm whether the factory definition in the configuration is a direct PHP callable (e.g., a closure) or a string referencing a class name.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 22 Jan 2024, 16:03 UTC
The answer correctly notes that PHP historically ignores extra arguments, but this changes in PHP 8.1+ where ArgumentCountError is thrown when a callable declares fewer required parameters than provided. A ZF3-style factory written as function($container) { ... } will fail under PHP 8.2 with laminas/laminas-servicemanager ^3.10 because the container invokes it with three arguments.
ArgumentCountError, every legacy factory must be updated to accept ContainerInterface $container, string $requestedName, array $options = null.This check takes seconds and prevents silent runtime failures after cache clears.