Skip to content

Loading…

DDC-77: PHP Warning when trying to skip non-existaint Annotations #5284

Closed
doctrinebot opened this Issue · 7 comments

1 participant

@doctrinebot

Jira issue originally created by user @beberlei:

If you have a docblock that ends with an annotation, for example:

/****
 * @return
 */

it throws a PHP warnings, because issubclassof() requires the $class to be existent.

Fix: Add class_exists($name) before.

@doctrinebot

Comment created by @beberlei:

Fixed in r6583, first commit \o/

However, I cant change the assignee here now anymore.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by romanb:

Would classexists(..., false) work, too? Because by default class_exists might trigger autoloading and this is sometimes not wanted for performance reasons (if a class does not exist, each call to class_exists might trigger autoload *again for that class, over and over). So if possible, always do class_exists(...., false) unless you really have the intention that autoloading is invoked, then use class*exists(..., true) to make that clear.

@doctrinebot

Comment created by @beberlei:

Isn't that what the caching is for in the first place?

But yes, there could be another layer that caches the class_exists calls, however then the complete condition has to be extracted into a method (which would probably be good anyhow, since its not readable).

@doctrinebot

Comment created by romanb:

What caching? Probably you misunderstood me. The second parameter of class_exists defaults to true which can have unwanted consequences with ugly autoloaders.

I changed it to class_exists($name, false) and your test still runs fine, so I guess its ok.

Even when you want autoload to be invoked I would recommend using explicitly: classexists($className, true) because that makes it clear that it is intended. I've seen many times that people did not even know that autoload was invoked on classexists :)

@doctrinebot

Comment created by @beberlei:

Ah ok, well my intention was to use autoloading, because otherwise the code behaves differently when the annotations are loaded and when they are not which is not obvious from the outside I think.

@doctrinebot

Comment created by chebba:

With class_exists(..., false) it's hard to use this part of library somewhere with custom annotations and autoloading. If we create some custom annotations we always need to load them all before we can use reader.
May be it will be better to autoload annotations with class_exists(..., true), but filter PhpDoc tags? or separate tags and annotations in some way?

@doctrinebot doctrinebot added this to the 2.0-ALPHA3 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.