Skip to content

Commit 8e884e7

Browse files
committed
Merge pull request #20 from ciaranmcnulty/bugfix/php-56-reflection-internal-final
Cannot instantiate final class if it extends internal
2 parents b70d227 + 6e8cfc5 commit 8e884e7

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/Doctrine/Instantiator/Instantiator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private function attemptInstantiationViaUnSerialization(ReflectionClass $reflect
197197
private function isInstantiableViaReflection(ReflectionClass $reflectionClass)
198198
{
199199
if (\PHP_VERSION_ID >= 50600) {
200-
return ! ($reflectionClass->isInternal() && $reflectionClass->isFinal());
200+
return ! ($this->hasInternalAncestors($reflectionClass) && $reflectionClass->isFinal());
201201
}
202202

203203
return \PHP_VERSION_ID >= 50400 && ! $this->hasInternalAncestors($reflectionClass);

tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public function getInstantiableClasses()
169169
array('PharException'),
170170
array('DoctrineTest\\InstantiatorTestAsset\\SimpleSerializableAsset'),
171171
array('DoctrineTest\\InstantiatorTestAsset\\ExceptionAsset'),
172+
array('DoctrineTest\\InstantiatorTestAsset\\FinalExceptionAsset'),
172173
array('DoctrineTest\\InstantiatorTestAsset\\PharExceptionAsset'),
173174
array('DoctrineTest\\InstantiatorTestAsset\\UnCloneableAsset'),
174175
array('DoctrineTest\\InstantiatorTestAsset\\XMLReaderAsset'),
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*
3+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
*
15+
* This software consists of voluntary contributions made by many individuals
16+
* and is licensed under the MIT license. For more information, see
17+
* <http://www.doctrine-project.org>.
18+
*/
19+
20+
namespace DoctrineTest\InstantiatorTestAsset;
21+
22+
use BadMethodCallException;
23+
use Exception;
24+
25+
/**
26+
* Test asset that extends an internal PHP base exception
27+
*
28+
* @author Marco Pivetta <[email protected]>
29+
*/
30+
final class FinalExceptionAsset extends Exception
31+
{
32+
/**
33+
* Constructor - should not be called
34+
*
35+
* @throws BadMethodCallException
36+
*/
37+
public function __construct()
38+
{
39+
throw new BadMethodCallException('Not supposed to be called!');
40+
}
41+
}

0 commit comments

Comments
 (0)