Home » Database » DB_DataObject_FormBuilder » Bug #866
PEAR QA: improvement for get_class()-usage
Details
| Submitted | 2004-02-26 13:25 UTC |
|---|---|
| From | pear-qa at lists dot php dot net |
| Assigned | mw21st |
| Status | Bogus |
| Package | DB_DataObject_FormBuilder |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2004-02-26 13:25 UTC] pear-qa at lists dot php dot net
Description:
------------
## from the PEAR QA team ##
## quality-assurance related ##
Please note that if you don't react to this issue within 4 weeks the PEAR QA-team will take care of it automatically. This is not "rude" but necessary for QA.
If this is a "false positive" and your package is not affected please apologize.
This package uses get_class()-calls without care for case-sensitivity of the returned classnames. In PHP 4.x the default for getclass() was that lowercase classnames were returned. However, due to extended DOM functionality, PHP 5.x returns classnames with correct upper-and-lowercase.
If you intend to run your package under both PHP4 and PHP5 please consider using case-independent comparisons or apply case-fixes.
Found in:
FILE: '/cvs/php/pear/DB_DataObject_FormBuilder/FormBuilder.php' :
/cvs/php/pear/DB_DataObject_FormBuilder/FormBuilder.php(303): $formName = get_class($this->_do);
/cvs/php/pear/DB_DataObject_FormBuilder/FormBuilder.php(742): $this->debug('Error: '.get_class($opts).' does not inherit from DB_DataObject');
Reproduce code:
---------------
Affected are constructs like:
if (get_class($foo) == 'foo') {
...
}
Possible solutions for correct class-checks:
strtolower(get_class($foo)) == 'foo'
is_a($foo, 'foo')
!strcasecmp(get_class($foo), 'foo')
[2004-03-14 17:47 UTC] mw21st at php dot net
The usage of get_class() is only for purposes of displaying the class name of an object and is not used for function-relevant operations.
However, I often use things like:
if(is_a($opts, 'db_dataobject')) { ...
Will that still work?