Last active
August 29, 2015 14:05
-
-
Save adamlundrigan/e185f654a04e782a11a6 to your computer and use it in GitHub Desktop.
PoC of Zend\ServiceManager bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* | |
!.gitignore | |
!run.php | |
!composer.json | |
!result.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "adamlundrigan/sm_bug_poc", | |
"authors": [ | |
{ | |
"name": "Adam Lundrigan", | |
"email": "[email protected]" | |
} | |
], | |
"require": { | |
"zendframework/zendframework": "dev-master@dev" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adam@adampc:/var/www/zf2/sm_bug_poc$ php run.php | |
PHP Warning: assert(): Assertion failed in /var/www/zf2/sm_bug_poc/run.php on line 42 | |
PHP Stack trace: | |
PHP 1. {main}() /var/www/zf2/sm_bug_poc/run.php:0 | |
PHP 2. assert() /var/www/zf2/sm_bug_poc/run.php:42 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/vendor/autoload.php'; | |
use Zend\ServiceManager\ServiceManager; | |
use Zend\ServiceManager\Config; | |
class MyTestService {} | |
$mainManager = new ServiceManager( | |
new Config( | |
array( | |
'invokables' => array( 'foo_service' => 'MyTestService' ), | |
'shared' => array( 'foo_service' => false ), | |
) | |
) | |
); | |
// Test #1 - Retrieve non-shared service from main SM twice | |
$obj1 = $mainManager->get('foo_service'); | |
$obj2 = $mainManager->get('foo_service'); | |
assert($obj1 !== $obj2); | |
// Test #2 - Retrieve non-shared service from child SM twice when peer SM is checked first | |
$childManager = new ServiceManager(new Config()); | |
$childManager->addPeeringServiceManager($mainManager); | |
$childManager->setRetrieveFromPeeringManagerFirst(true); | |
$obj1 = $childManager->get('foo_service'); | |
$obj2 = $childManager->get('foo_service'); | |
assert($obj1 !== $obj2); | |
// Test #3 - Retrieve non-shared service from child SM twice when peer SM is not checked first | |
$childManager = new ServiceManager(new Config()); | |
$childManager->addPeeringServiceManager($mainManager); | |
$childManager->setRetrieveFromPeeringManagerFirst(false); | |
$obj1 = $childManager->get('foo_service'); | |
$obj2 = $childManager->get('foo_service'); | |
assert($obj1 !== $obj2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment