Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bug fix for GlobIterator extending service #3813

Merged
merged 1 commit into from

2 participants

@EvanDotPro
Collaborator

Reported by andrer on IRC... If a service extends GlobIterator, there
was a problem where we were checking if (!$instance) which would yield a
catchable fatal error that GlobIterator cannot be casted to a boolean.
To solve this, the comparison operators should be strict so PHP does not
try to convert the type internally. The types checked against are the
expected types if no services have been returned, so the overall
behavior should not be changed by this fix at all.

@EvanDotPro EvanDotPro Bug fix for GlobIterator extending service
Reported by andrer on IRC... If a service extends GlobIterator, there
was a problem where we were checking if (!$instance) which would yield a
catchable fatal error that GlobIterator cannot be casted to a boolean.
To solve this, the comparison operators should be strict so PHP does not
try to convert the type internally. The types checked against are the
expected types if no services have been returned, so the overall
behavior should not be changed by this fix at all.
d66fd64
@ralphschindler ralphschindler merged commit d66fd64 into zendframework:master
@ralphschindler ralphschindler referenced this pull request from a commit
@ralphschindler ralphschindler Forward #3813 a5f01b0
@ghost Unknown referenced this pull request from a commit
@ralphschindler ralphschindler Forward #3813 6ff6d21
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-servicemanager
@ralphschindler ralphschindler Forward zendframework/zf2#3813 bd11849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2013
  1. @EvanDotPro

    Bug fix for GlobIterator extending service

    EvanDotPro authored
    Reported by andrer on IRC... If a service extends GlobIterator, there
    was a problem where we were checking if (!$instance) which would yield a
    catchable fatal error that GlobIterator cannot be casted to a boolean.
    To solve this, the comparison operators should be strict so PHP does not
    try to convert the type internally. The types checked against are the
    expected types if no services have been returned, so the overall
    behavior should not be changed by this fix at all.
This page is out of date. Refresh to see the latest.
View
6 library/Zend/ServiceManager/ServiceManager.php
@@ -445,7 +445,7 @@ public function get($name, $usePeeringServiceManagers = true)
}
// Still no instance? raise an exception
- if (!$instance && !is_array($instance)) {
+ if ($instance === null && !is_array($instance)) {
if ($isAlias) {
throw new Exception\ServiceNotFoundException(sprintf(
'An alias "%s" was requested but no service could be found.',
@@ -494,11 +494,11 @@ public function create($name)
$instance = $this->createFromFactory($cName, $rName);
}
- if (!$instance && isset($this->invokableClasses[$cName])) {
+ if ($instance === false && isset($this->invokableClasses[$cName])) {
$instance = $this->createFromInvokable($cName, $rName);
}
- if (!$instance && $this->canCreateFromAbstractFactory($cName, $rName)) {
+ if ($instance === false && $this->canCreateFromAbstractFactory($cName, $rName)) {
$instance = $this->createFromAbstractFactory($cName, $rName);
}
View
12 tests/ZendTest/ServiceManager/ServiceManagerTest.php
@@ -560,6 +560,18 @@ public function testShouldRaiseExceptionIfInitializerClassIsNotAnInitializerInte
$result = $this->serviceManager->addInitializer(get_class($this));
}
+ public function testGetGlobIteratorServiceWorksProperly()
+ {
+ $config = new Config(array(
+ 'invokables' => array(
+ 'foo' => 'ZendTest\ServiceManager\TestAsset\GlobIteratorService',
+ ),
+ ));
+ $serviceManager = new ServiceManager($config);
+ $foo = $serviceManager->get('foo');
+ $this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\GlobIteratorService', $foo);
+ }
+
public function duplicateService()
{
$self = $this;
View
19 tests/ZendTest/ServiceManager/TestAsset/GlobIteratorService.php
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_ServiceManager
+ */
+
+namespace ZendTest\ServiceManager\TestAsset;
+
+class GlobIteratorService extends \GlobIterator
+{
+ public function __construct()
+ {
+ }
+}
+
Something went wrong with that request. Please try again.