Edit report at https://bugs.php.net/bug.php?id=63665&edit=1

 ID:                 63665
 Updated by:         dmi...@php.net
 Reported by:        dev at jurajsplayground dot com
 Summary:            Relative namespace import causes getClass() method
                     to throw an exception
-Status:             Assigned
+Status:             Not a bug
 Type:               Bug
 Package:            Reflection related
 Operating System:   Ubuntu
 PHP Version:        5.4.9
 Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

PHP doesn't support *relative* namespace import. A name from "use" statement is 
always used as a full namespace name.


Previous Comments:
------------------------------------------------------------------------
[2012-12-02 05:52:11] larue...@php.net

I have tried to make a fix, but for such situation

use \Foo;  CG(current_import) only hold the Foo name but doesn't hold the 
global 
name flag..

so, I can not simply resolve the full name of a class name which is imported 
and 
in a namespace.

------------------------------------------------------------------------
[2012-12-02 05:22:58] larue...@php.net

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?

------------------------------------------------------------------------
[2012-12-01 23:10:49] 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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63665&edit=1

Reply via email to