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

 ID:                 63665
 Updated by:         [email protected]
 Reported by:        dev at jurajsplayground dot com
 Summary:            Relative namespace import causes getClass() method
                     to throw an exception
 Status:             Open
 Type:               Bug
 Package:            Reflection related
 Operating System:   Ubuntu
 PHP Version:        5.4.9
-Assigned To:        
+Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

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?


Previous Comments:
------------------------------------------------------------------------
[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