Req #66927 [Opn->Csd]: Request new type operator "exhibits"
| From: | kalle@php.net | Date: | Sat, 06 Aug 2016 03:06:34 +0000 |
| Subject: | Req #66927 [Opn->Csd]: Request new type operator "exhibits" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202987@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
Updated by: kalle@php.net
Reported by: rdanner at gmail dot com
Summary: Request new type operator "exhibits"
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: *General Issues
Operating System: Ubuntu 12.04 LTS
PHP Version: 5.4.26
-Assigned To:
+Assigned To: kalle
Block user comment: N
Private report: N
New Comment:
Or maybe we could instead just modify the instanceof operator to support traits too, as
classes/interfaces/traits all internally uses the same symbol table for naming, meaning this is
disallowed:
trait A {}
interface A {} // Error, name is already in use
I suggest bringing this up at the mailing list (internals@) and perhaps consider writing an RFC for
this that can target 7.2, as its too late for 7.1
Previous Comments:
------------------------------------------------------------------------
[2015-02-08 10:56:48] minecraftshamrock at gmail dot com
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.
------------------------------------------------------------------------
[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