| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2012-12-01 23:10 UTC] dev at jurajsplayground dot com
 Description:
------------
While importing of namespaced classes via relative namespace directive works when 
creating objects, ReflectionParameter::getClass() has a problem with it and 
throws an exception that such class cannot be found.
Test script:
---------------
namespace Foo\Bar;
use A\B\BInterface;
class Bar implements BarInterface {
	public function __construct()
	{
		echo "Hello!";
	}
	public function getSomething(BInterface $b){}
}
namespace Foo\Bar;
use A\B\BInterface;
interface BarInterface {
	public function getSomething(BInterface $b);
}
namespace Foo\Bar\A\B;
interface BInterface {}
namespace TestNamespace;
$obj = new \Foo\Bar\Bar();
$ref = new \ReflectionMethod("\\Foo\Bar\Bar", "getSomething");
echo current($ref->getParameters())->getClass();
Expected result:
----------------
Should display interface information
Actual result:
--------------
ReflectionException is thrown: Class A\B\BInterface does not exist
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 09:00:01 2025 UTC | 
actually, this is not a only reflection specific issue. <?php namespace Foo\Bar\A\B; interface BInterface {} class Foo implements BInterface { } namespace Foo\Bar; use A\B\BInterface; class Bar implements BarInterface { public function __construct() { echo "Hello!"; } public function getSomething(BInterface $b){} } interface BarInterface { public function getSomething(BInterface $b); } namespace TestNamespace; use Foo\Bar\A\B; $obj = new \Foo\Bar\Bar(); $arg = new \Foo\Bar\A\B\Foo; $obj->getSomething($arg); PHP Catchable fatal error: Argument 1 passed to Foo\Bar\Bar::getSomething() must be an instance of A\B\BInterface, instance of Foo\Bar\A\B\Foo given, called in /tmp/1.php on line 30 and defined in /tmp/1.php on line 18 dmitry, could you please look at this one?