|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-03-18 17:29 UTC] 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!
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 01:00:01 2025 UTC |
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