diff --git a/src/ServiceManager.php b/src/ServiceManager.php index 1396892d..59f775e3 100644 --- a/src/ServiceManager.php +++ b/src/ServiceManager.php @@ -668,6 +668,12 @@ private function getFactory($name) if ($lazyLoaded) { $this->factories[$name] = $factory; } + // PHP 5.6 fails on 'class::method' callables unless we explode them: + if (PHP_MAJOR_VERSION < 7 + && is_string($factory) && strpos($factory, '::') !== false + ) { + $factory = explode('::', $factory); + } return $factory; } diff --git a/test/ServiceManagerTest.php b/test/ServiceManagerTest.php index 094951a6..8c559946 100644 --- a/test/ServiceManagerTest.php +++ b/test/ServiceManagerTest.php @@ -267,4 +267,20 @@ public function testSetAliasShouldWorkWithRecursiveAlias() $this->assertSame($service, $alias); $this->assertSame($service, $headAlias); } + + public static function sampleFactory() + { + return new stdClass(); + } + + public function testFactoryMayBeStaticMethodDescribedByCallableString() + { + $config = [ + 'factories' => [ + stdClass::class => 'ZendTest\ServiceManager\ServiceManagerTest::sampleFactory', + ] + ]; + $serviceManager = new SimpleServiceManager($config); + $this->assertEquals(stdClass::class, get_class($serviceManager->get(stdClass::class))); + } }