DDC-876: CLI Global namespace forced on all Entity generated TypeHinting #1090

Closed
opened 2026-01-22 13:01:37 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 12, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user santananl:

When using the CLI tool to generate your entities Doctrine forces a global namespace on all TypeHints in functions. For example I used the sandbox

See file User.php with function setAddress:

public function setAddress(Address $address)

Remove this function entirely, so that it can be generated. Then run,

./doctrine orm:generate-entities .

Open file User.php and now the function has become:

public function setAddress(\Address $address)

note the prepended \ for global namespace

This behaviour would be fine if all types would be in the global scope, but they're not. If you use another entity such as Address in the same namespace it should just generate the proper
public function setAddress(Address $address)

Or better yet, generate the Fully Qualified Namespace

Code responsible for this:
http://trac.doctrine-project.org/browser/trunk/lib/Doctrine/ORM/Tools/EntityGenerator.php#L609

Originally created by @doctrinebot on GitHub (Nov 12, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user santananl: When using the CLI tool to generate your entities Doctrine forces a global namespace on all TypeHints in functions. For example I used the sandbox See file User.php with function setAddress: # public function setAddress(Address $address) Remove this function entirely, so that it can be generated. Then run, # ./doctrine orm:generate-entities . Open file User.php and now the function has become: # public function setAddress(\Address $address) note the prepended \ for global namespace This behaviour would be fine if all types would be in the global scope, but they're not. If you use another entity such as Address in the same namespace it should just generate the proper public function setAddress(Address $address) Or better yet, generate the Fully Qualified Namespace Code responsible for this: http://trac.doctrine-project.org/browser/trunk/lib/Doctrine/ORM/Tools/EntityGenerator.php#L609
admin added the Bug label 2026-01-22 13:01:37 +01:00
admin closed this issue 2026-01-22 13:01:39 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2010):

Comment created by @beberlei:

sorry but the code you highlight here on trac is 7 months old, the current code is on Git: www.github.com/doctrine/doctrine2

Are you really using Beta 4?

@doctrinebot commented on GitHub (Nov 13, 2010): Comment created by @beberlei: sorry but the code you highlight here on trac is 7 months old, the current code is on Git: www.github.com/doctrine/doctrine2 Are you really using Beta 4?
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2010):

Comment created by santananl:

yes I'm using beta 4 It's a PEAR install.

Sorry for the outdated URL, here's the proper one.

https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/EntityGenerator.php#L591

@doctrinebot commented on GitHub (Nov 13, 2010): Comment created by santananl: yes I'm using beta 4 It's a PEAR install. Sorry for the outdated URL, here's the proper one. https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/EntityGenerator.php#L591
Author
Owner

@doctrinebot commented on GitHub (Nov 27, 2010):

Comment created by @beberlei:

Ah i know what is causing this issue.

The Disconnected Metadata factory cannot know which namespace the class is in. Are you generating the code from XML or YAML?

@doctrinebot commented on GitHub (Nov 27, 2010): Comment created by @beberlei: Ah i know what is causing this issue. The Disconnected Metadata factory cannot know which namespace the class is in. Are you generating the code from XML or YAML?
Author
Owner

@doctrinebot commented on GitHub (Nov 27, 2010):

Comment created by santananl:

No XML or YAML in this setup, just class files and an SQL based backend

@doctrinebot commented on GitHub (Nov 27, 2010): Comment created by santananl: No XML or YAML in this setup, just class files and an SQL based backend
Author
Owner

@doctrinebot commented on GitHub (Nov 27, 2010):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Nov 27, 2010): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Nov 27, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Nov 27, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1090