Edit report at https://bugs.php.net/bug.php?id=55266&edit=1
ID: 55266 Updated by: g...@php.net Reported by: mchlpl at gmail dot com Summary: Traits vs Type hints -Status: To be documented +Status: Closed Type: Bug Package: Class/Object related PHP Version: 5.4.0alpha2 -Assigned To: +Assigned To: gron Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2011-10-16 18:46:46] g...@php.net This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. ------------------------------------------------------------------------ [2011-07-23 19:13:19] g...@php.net Added class_uses(..) in SPL to mirror existing class_implements(..) per http://svn.php.net/viewvc?view=revision&revision=313640 ------------------------------------------------------------------------ [2011-07-23 19:08:36] g...@php.net Automatic comment from SVN on behalf of gron Revision: http://svn.php.net/viewvc/?view=revision&revision=313640 Log: Added missing class_uses(..) function to SPL to mirror class_implements(..). # Was pointed out as missing in bug #55266. ------------------------------------------------------------------------ [2011-07-23 07:47:49] g...@php.net My view on this issue is that traits do not constitute types and do not provide interfaces. (I proposed the later one in the beginning in the sense of traits are interfaces with implementation, but this was disregarded to make clear that traits are neither classes nor interfaces.) Thus, is_a should also not say anything about a trait. Traits are not units of encapsulation, they do not guarantee to provide/protect any invariants. However, if you need to know what traits are used by a class, please refer to: ReflectionClass::getTraits() I just noticed that we have the following function in the SPL: http://php.net/manual/en/function.class-implements.php That should probably be mirrored to provide the same functionality as ReflectionClass::getTraits(). Not sure what the design policies are here. From a symmetry perspective there should be a class_uses() function, but from my personal perspective, class_implements should get nuked and uses should transition to the reflection extension if they need such meta programming facilities. Well, the later is not practical, so we will probably need to have class_uses(). ------------------------------------------------------------------------ [2011-07-22 14:51:09] alex dot howansky at gmail dot com > $a is not an instance of the trait but rather of > the class that utilizes the trait. You can say the same of interfaces and abstracts, but is_a returns true for them. Test script: --------------- trait someTrait {} interface someInterface {} abstract class someAbstract {} class someClass extends someAbstract implements someInterface { use someTrait; } $a = new someClass(); var_dump(is_a($a, 'someClass')); var_dump(is_a($a, 'someAbstract')); var_dump(is_a($a, 'someInterface')); var_dump(is_a($a, 'someTrait')); Expected result: ---------------- bool(true) bool(true) bool(true) bool(?) Actual result: ---------------- bool(true) bool(true) bool(true) bool(false) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=55266 -- Edit this bug report at https://bugs.php.net/bug.php?id=55266&edit=1