note 78047 added to function.get-declared-classes
| From: | dexen+goofy_pl at osu1 dot php dot net | Date: | Tue, 25 Sep 2007 18:32:52 +0000 |
| Subject: | note 78047 added to function.get-declared-classes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130782@lists.php.net to get a copy of this message | ||
Summary:
* in PHP 5.1 class names have case preserved
* contrary, in PHP 4.4 class names are downcased, withe exception of a few build-in ones
The get_declared_classes() funcition returns the list of names with case preserved, as of PHP 5.1
series (prolly 5.0 too, but i have no way to test it right now). Since PHP generally is caseless in
regard to names of classes, this may come at a surprise. Also, this could potentially break older
code asssuming downcased list.
Take extra care when checking for existence of a class. Following example is, potentially, error
prone: <?php in_array( $className, $classget_declared_classes() ) ?>
A sure-fire (while slower) way would be to iterate over the array and normalize case to, say, lower:
<?php
$exists = FALSE;
$className = strtolower( $className );
foreach ( get_declared_classes() as $c ) {
if ( $className === strtolower( $c ) ) {
$exists = TRUE;
break;
}
}?>
Optimization of the above snippet is left as a simple excercise to the reader ;)
-- dexen deVries
----
Server IP: 195.136.184.34
Probable Submitter: 195.248.88.243
----
Manual Page -- http://www.php.net/manual/en/function.get-declared-classes.php
Edit -- https://master.php.net/note/edit/78047
Del: integrated -- https://master.php.net/note/delete/78047/integrated
Del: useless -- https://master.php.net/note/delete/78047/useless
Del: bad code -- https://master.php.net/note/delete/78047/bad+code
Del: spam -- https://master.php.net/note/delete/78047/spam
Del: non-english -- https://master.php.net/note/delete/78047/non-english
Del: in docs -- https://master.php.net/note/delete/78047/in+docs
Del: other reasons-- https://master.php.net/note/delete/78047
Reject -- https://master.php.net/note/reject/78047
Search -- https://master.php.net/manage/user-notes.php