Skip to content

[HttpKernel] add use statement for phpdoc #11802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

Miliooo
Copy link
Contributor

@Miliooo Miliooo commented Aug 29, 2014

Q A
Fixed tickets #11801
License MIT

Added use statement for the Phpdoc

| Q             | A
| ------------- | ---
| Fixed tickets | symfony#11801
| License       | MIT
@dunglas
Copy link
Member

dunglas commented Aug 29, 2014

Better change the PHPDoc to a fully qualified name than add an (unused) use statement.

@stof
Copy link
Member

stof commented Aug 29, 2014

@dunglas nope. Our coding standards are to use the short name in the phpdoc

@stof
Copy link
Member

stof commented Aug 29, 2014

👍

note to maintainers: this should go in 2.3

@fabpot
Copy link
Member

fabpot commented Aug 30, 2014

👍

@fabpot
Copy link
Member

fabpot commented Aug 30, 2014

Thank you @Miliooo.

fabpot added a commit that referenced this pull request Aug 30, 2014
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11802).

Discussion
----------

[HttpKernel] add use statement for phpdoc

| Q             | A
| ------------- | ---
| Fixed tickets | #11801
| License       | MIT

Added use statement for the Phpdoc

Commits
-------

0010fba [HttpKernel] add use statement for phpdoc
@fabpot fabpot closed this Aug 30, 2014
@dunglas
Copy link
Member

dunglas commented Aug 30, 2014

@stof for my curiosity, do you have a link or an explanation of why to do that? Thanks.

@dunglas
Copy link
Member

dunglas commented Aug 30, 2014

By the way, the PSR-5 draft (PHPDoc) recommends to always use the Fully Qualified Class Name in DocBlock: https://github.com/php-fig/fig-standards/pull/169/files#diff-9a10a11696dc38209c125ea9c57a565fR1891

@stof
Copy link
Member

stof commented Aug 30, 2014

@dunglas the section you link is not telling that. It is saying that tools processing the phpdoc should resolve relative names to FQCN as soon as possible to make the processing easier (i.e. not having to remember the context). There is no recommendation at all about the way to write the class names in the phpdoc here

@dunglas
Copy link
Member

dunglas commented Aug 30, 2014

@stof yes I've misunderstood the statement. But why add a use statement just for the PHPDoc? Importing unused classes cannot have a bad impact on performances (I don't know, I just ask)?

@wouterj
Copy link
Member

wouterj commented Aug 30, 2014

@dunglas it makes PHPdocs a lot easier to read (especially when having namespaces as long as Symfony has).

@Miliooo Miliooo deleted the patch-1 branch August 30, 2014 16:00
@stof
Copy link
Member

stof commented Aug 30, 2014

@dunglas it cannot impact the performance if you use opcache. Use statements are resolved early in the compilation of the code, and this is done only once in prod when you can the opcodes

@dunglas
Copy link
Member

dunglas commented Aug 30, 2014

@stof thanks for the explanation :)

@Miliooo
Copy link
Contributor Author

Miliooo commented Aug 30, 2014

@stof are you sure this needed to be merged in the 2.3 branch.
See 0ab9c8d

I'm no expert in this but it seems this class was only added in 2.4.

@apfelbox
Copy link
Contributor

@dunglas that is wrong. Classes are not autoloaded before they are actually used.
The use statement is nothing more than a hint for the following code so that the interpreter knows where to find your (short) class names.

See:
http://3v4l.org/rkp79

@dunglas
Copy link
Member

dunglas commented Aug 31, 2014

@apfelbox thanks for the link.

@stof
Copy link
Member

stof commented Aug 31, 2014

@apfelbox I'm not talking about the autoloading, but about the resolution of the name. Names are resolved even if the class does not exist.
Btw, this is exactly why a Java-like syntax use Foo\* cannot be implemented in PHP, as it would require knowing which classes exist in the Foo namespace.

@apfelbox
Copy link
Contributor

@stof I know that, but @dunglas was talking about the autoloading. 😉

a.k.a. there is no performance impact, because there is no autoloading (exactly due to the reason you described: in PHP the direction is reversed: local class name -> FQN -> autoload instead of Java's import (= autoload) -> FQN -> local class name).

@dunglas
Copy link
Member

dunglas commented Aug 31, 2014

@apfelbox I've not talked about autoloading. Just about performances (and according to @stof there is a non-significative performance impact when using an opcode cache, and a more significative one when not using a cache).

@apfelbox
Copy link
Contributor

Ah, okay, sorry - misunderstood.

But since the only thing affecting runtime performance here would be autoloading (and it doesn't happen), we can conclude that there is no impact. Right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants