beberlei / assert

Thin assertion library for use in libraries and business-model
Other
2.41k stars 188 forks source link

subclassOf() of assertion doesn't checks for class existence #231

Closed elpiel closed 7 years ago

elpiel commented 7 years ago

Is there a reason why the subclassOf() doesn't check if the passed $className exists or not?

I've just checked in PHP documentation, they also don't check that(tested with code) and btw it's not clear if PHP checks it or not in the documetation.

rquadling commented 7 years ago

The intent of the assertion is to determine if there is an appropriate extends. If the class cannot be found (either because the class is already known, or via autoloading), then whilst it may be inappropriate, it does deny the fact that class A can extend class B and therefore A is a subclass of B. It just means no one has a clue what a B is, but A sure does extend from it!

rquadling commented 7 years ago

Consider also that is_subclass_of() will use an autoloader if there is one present, class_exists() would seem redundant.