Created
March 1, 2013 13:53
-
-
Save docteurklein/5064805 to your computer and use it in GitHub Desktop.
failing test case for ReflectionMethod::getPrototype() when a class is using a trait that defines a method, chich class extends another class that defines the same method too.
This file contains 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 | |
trait TestTrait | |
{ | |
public function getKernel() | |
{ | |
} | |
} | |
class BaseTest | |
{ | |
public function getKernel() | |
{ | |
} | |
} | |
class Test extends BaseTest | |
{ | |
use TestTrait; | |
} | |
$refl = new \ReflectionClass('Test'); | |
var_dump($refl->getMethod('getKernel')->getPrototype()); | |
var_dump($refl->getMethod('getKernel')->getPrototype()->getPrototype()->getPrototype()->getPrototype()->getPrototype()->getPrototype()->getPrototype()->getPrototype()->getPrototype()->getPrototype()->getPrototype()); |
PHP Version:
PHP 5.4.6-1ubuntu1.1 (cli) (built: Nov 15 2012 01:18:34)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
Result:
class ReflectionMethod#3 (2) {
public $name =>
string(9) "getKernel"
public $class =>
string(8) "BaseTest"
}
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Method BaseTest::getKernel does not have a prototype' in /home/antoine/htdocs/plop/foo.php:26
Stack trace:
#0 /home/antoine/htdocs/plop/foo.php(26): ReflectionMethod->getPrototype()
#1 {main}
thrown in /home/antoine/htdocs/plop/foo.php on line 26
Fatal error: Uncaught exception 'ReflectionException' with message 'Method BaseTest::getKernel does not have a prototype' in /home/antoine/htdocs/plop/foo.php on line 26
ReflectionException: Method BaseTest::getKernel does not have a prototype in /home/antoine/htdocs/plop/foo.php on line 26
Call Stack:
0.0002 239304 1. {main}() /home/antoine/htdocs/plop/foo.php:0
0.0003 241328 2. ReflectionMethod->getPrototype() /home/antoine/htdocs/plop/foo.php:26
PHP Version
clemherreman≻ macclem≻ ~ ≻ Boulot ≻ Perso ≻ $ ≻php -v
PHP 5.4.3 (cli) (built: Jun 6 2012 11:03:31)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
Result
clemherreman≻ macclem≻ ~ ≻ Boulot ≻ Perso ≻ $ ≻php gistfile1.php
class ReflectionMethod#3 (2) {
public $name =>
string(9) "getKernel"
public $class =>
string(8) "BaseTest"
}
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Method BaseTest::getKernel does not have a prototype' in /Users/clemherreman/Boulot/Perso/gistfile1.php:26
Stack trace:
#0 /Users/clemherreman/Boulot/Perso/gistfile1.php(26): ReflectionMethod->getPrototype()
#1 {main}
thrown in /Users/clemherreman/Boulot/Perso/gistfile1.php on line 26
PHP 5.5.5 (cli) (built: Oct 16 2013 05:59:03)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
<?php
class MyMethod extends \ReflectionMethod {
public function hasPrototype() {
try {
parent::getPrototype();
return true;
}
catch (\ReflectionException $e) {
return false;
}
}
public function getPrototype() {
return $this->hasPrototype() ? parent::getPrototype() : "Method {$this->getName()} does not have a prototype";
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results with: