note 110912 modified in function.class-uses by googleguy

From: Date: Sat, 22 Dec 2012 05:21:56 +0000
Subject: note 110912 modified in function.class-uses by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192646@lists.php.net to get a copy of this message
[Edited by: googleguy at php dot net for clarity. It's obvious Xyz should have been Trait and not Class. ] If your objective is to determine if a trait is being used by another class, you cannot use instanceOf... <?php Trait Xyz { } class Abc { use Xyz; } $abc = new Abc(); var_dump($abc instanceOf Xyz); // false ?> You must use this function with either an in_array or array_key_exists... <?php var_dump(array_key_exists('Xyz', class_uses($abc))); //true ?> --was-- If your objective is to determine if a trait is being used by another class, you cannot use instanceOf... <?php class Abc { use Xyz; } class Xyz { } $abc = new Abc(); var_dump($abc instanceOf Xyz); // false ?> You must use this function with either an in_array or array_key_exists... <?php var_dump(array_key_exists('Xyz', class_uses($abc))); //true ?> http://php.net/manual/en/function.class-uses.php

« previous php.notes (#192646) next »