Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 4b96db8

Browse files
committed
Fix problem with string callables failing in PHP 5.6.
1 parent fc81dee commit 4b96db8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/ServiceManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ private function getFactory($name)
668668
if ($lazyLoaded) {
669669
$this->factories[$name] = $factory;
670670
}
671+
// PHP 5.6 fails on 'class::method' callables unless we explode them:
672+
if (is_string($factory) && strpos($factory, '::') !== false) {
673+
$factory = explode('::', $factory);
674+
}
671675
return $factory;
672676
}
673677

test/ServiceManagerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,20 @@ public function testSetAliasShouldWorkWithRecursiveAlias()
267267
$this->assertSame($service, $alias);
268268
$this->assertSame($service, $headAlias);
269269
}
270+
271+
public static function sampleFactory()
272+
{
273+
return new stdClass();
274+
}
275+
276+
public function testStaticCallable()
277+
{
278+
$config = [
279+
'factories' => [
280+
stdClass::class => 'ZendTest\ServiceManager\ServiceManagerTest::sampleFactory',
281+
]
282+
];
283+
$serviceManager = new SimpleServiceManager($config);
284+
$this->assertEquals(stdClass::class, get_class($serviceManager->get(stdClass::class)));
285+
}
270286
}

0 commit comments

Comments
 (0)