mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-77: PHP Warning when trying to skip non-existaint Annotations #96
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Oct 30, 2009).
Jira issue originally created by user @beberlei:
If you have a docblock that ends with an annotation, for example:
it throws a PHP warnings, because is_subclass_of() requires the $class to be existent.
Fix: Add class_exists($name) before.
@doctrinebot commented on GitHub (Oct 30, 2009):
Comment created by @beberlei:
Fixed in r6583, first commit \o/
However, I cant change the assignee here now anymore.
@doctrinebot commented on GitHub (Oct 30, 2009):
Issue was closed with resolution "Fixed"
@doctrinebot commented on GitHub (Oct 30, 2009):
Comment created by romanb:
Would class_exists(..., 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 classexists(..., true) to make that clear.
@doctrinebot commented on GitHub (Oct 30, 2009):
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 commented on GitHub (Oct 30, 2009):
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: class_exists($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 class_exists :)
@doctrinebot commented on GitHub (Oct 30, 2009):
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 commented on GitHub (Apr 18, 2010):
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?