Edit report at https://bugs.php.net/bug.php?id=61265&edit=1

 ID:                 61265
 User updated by:    manchokapitancho at gmail dot com
 Reported by:        manchokapitancho at gmail dot com
 Summary:            __autoload should know about traits
 Status:             Open
 Type:               Feature/Change Request
 Package:            Class/Object related
 PHP Version:        5.4.0
 Block user comment: N
 Private report:     N

 New Comment:

Yes, there is a use case.
Currently, I use a workaround but in general, the idea behind is that after I 
locate the file, corresponding to the class name being autoloaded, 
I require_once the file and then check if the class is really inside 
(class_exists). As of 5.4, class_exists returns false for traits and I have to 
use 
class_exists || trait_exists. Not a big deal, really, but it is still possible 
to 
have different paths for classes (ex. /classes) and different one for traits 
(/traits).


Previous Comments:
------------------------------------------------------------------------
[2012-03-08 13:26:06] shiranai7 at hotmail dot com

Sorry.. it should say "It is NOT a critical feature" instead of "NOW".

------------------------------------------------------------------------
[2012-03-08 13:25:04] shiranai7 at hotmail dot com

It is now a critical feature but it would be nice. For example - if I decided 
to format the filenames depending on what is being autoloaded 
(class/interface/trait) I could not easily do it.

Adding a second argument to the autoload callback would make this possible and 
should not break anything.

------------------------------------------------------------------------
[2012-03-04 17:11:11] g...@php.net

Could you elaborate a bit on the usecase?
Until now, there didn't seem to be the need to handle interfaces differently in 
an  
autoloader. Why would you treat traits differently from classes and interfaces?

------------------------------------------------------------------------
[2012-03-03 13:10:25] manchokapitancho at gmail dot com

Description:
------------
Currently, __autoload is automatically called when a class is not found. As of 
5.4.0, it is also called when a trait is not found. It is also called when an 
interface is not found.
Unfortunately, there is no way to understand what type of resource is being 
autoloaded.
So I suggest that a second optional argument is added to __autoload. It can 
receive three possible values from the PHP engine - for example:
AUTOLOAD_CLASS, AUTOLOAD_TRAIT and AUTOLOAD_INSTANCE.
This way, a better autoload handling can be achieved.



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61265&edit=1

Reply via email to