Req #66927 [Com]: Request new type operator "exhibits"

From: Date: Sun, 08 Feb 2015 10:56:48 +0000
Subject: Req #66927 [Com]: Request new type operator "exhibits"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190530@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66927&edit=1 ID: 66927 Comment by: minecraftshamrock at gmail dot com Reported by: rdanner at gmail dot com Summary: Request new type operator "exhibits" Status: Open Type: Feature/Change Request Package: *General Issues Operating System: Ubuntu 12.04 LTS PHP Version: 5.4.26 Block user comment: N Private report: N New Comment: I agree that such an operator would improve readability. But what would you do with such an operator? Knowing that a class uses a specific trait is nice, but the class might have changed the name or visibility of any of the taits' members. Previous Comments: ------------------------------------------------------------------------ [2014-03-18 17:29:13] rdanner at gmail dot com Description: ------------ Much like the "instanceof" operator can be used to evaluate if a class is and instance of (or descendant of) a particular class, an "exhibits" keyword would be useful for evaluating if a class exhibits a particular trait: if ($baz exhibits someTrait) {} Test script: --------------- //Currently, this can be done with something along the lines of $ob = new someClass; // see if $ob is an instance of a class that exhibits the "neato" trait if (class_exists('someClass') and in_array('neato', class_uses($ob)) { // it does! } //but this would be much cleaner as: if ($ob exhibits neato) { // yup! } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66927&edit=1

« previous php.bugs (#190530) next »