Bug #46008

Reflection should resolve relative namespaces

Added by Christopher Hlubek over 8 years ago. Updated almost 8 years ago.

Status:
Resolved
Priority:
Should have
Category:
Reflection
Target version:
-
Start date:
2013-03-04
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

Annotations (e.g. @var) with relative class names are not resolved correctly under the namespace of the given class.
To have a correct handling of namespaces in PHP we should support the usage of relative class names in these places.

namespace MyVendor\MyPackage\Domain\Model;

class Foo {

    /**
     * @var Bar
     */
    protected $bar;

}
namespace MyVendor\MyPackage\Domain\Model;

class Bar {

}

Since this is a problem for some people (e.g. also PhpStorm uses relative class names when auto-completing) I consider this a bug we should solve in the framework.


Related issues

Related to TYPO3.Flow - Bug #50909: Dependency injection for imported namespaces fails for abstract classesResolvedBastian Waidelich2013-08-08

Actions
Related to TYPO3.Flow - Bug #57034: Dependency injection for imported namespaces fails for collection classesResolvedBastian Waidelich2014-03-18

Actions
Related to TYPO3 Core - Bug #57856: @inject does not work relative to current namespaceClosed2014-04-12

Actions
Related to TYPO3 Core - Bug #85932: Incorrect annotation for property "message" in class "Error".Closed2018-08-23

Actions
#1

Updated by Bastian Waidelich about 8 years ago

Probably we should also consider use statements:

namespace MyVendor\MyPackage\Domain\Model;

use MyVendor\MyPackage\Bar as Baz;

class Foo {

    /**
     * @var Baz
     */
    protected $baz;
}

but it seems PHP itself is buggy there https://bugs.php.net/bug.php?id=63665

#2

Updated by Bastian Waidelich about 8 years ago

Bastian Waidelich wrote:

but it seems PHP itself is buggy there https://bugs.php.net/bug.php?id=63665

This bug report seems is about something different it seems. This works as expected:

namespace Foo\Bar;

class Baz {

}

namespace MyPackage;
use Foo\Bar\Baz as Quux;

class Test {

    /**
     * @param Quux $param
     * @return void
     */
    public function test(Quux $param) {
    }
}

$reflectionMethod = new \ReflectionMethod('MyPackage\Test', 'test');
echo current($reflectionMethod->getParameters())->getClass();

Result:

Class [ class Foo\Bar\Baz ] { @@ test.php 4-6 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [0] { } }

#3

Updated by Sebastian Kurfuerst about 8 years ago

  • Status changed from New to Accepted
  • Assignee set to Sebastian Kurfuerst

I have a patch for this in the works; almost ready.

#4

Updated by Bastian Waidelich about 8 years ago

Sebastian Kurfuerst wrote:

I have a patch for this in the works; almost ready.

Great! Looking forward to this one

#5

Updated by Gerrit Code Review about 8 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158

#6

Updated by Gerrit Code Review almost 8 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158

#7

Updated by Gerrit Code Review almost 8 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158

#8

Updated by Gerrit Code Review almost 8 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158

#9

Updated by Sebastian Kurfuerst almost 8 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#10

Updated by Patryk Ostrowski almost 3 years ago

  • Related to Bug #85932: Incorrect annotation for property "message" in class "Error". added

Also available in: Atom PDF