Issues

ZF-11610: ctype_digit in Zend Framework

Description

ctype_digit has a very strange behavior in php. In most cases variable should be manualy cast to string.


$someVarIntOrNumericString;
//$isDigit = ctype_digit($someVarIntOrNumericString); //<= wrong
$isDigit = ctype_digit((string) $someVarIntOrNumericString); //right

Examples:


ctype_digits('123'); //true
ctype_digits(123); //false

// but ...
ctype_digits(ord('5')); //true

In ZF there are some places where cast to string is missing: * Zend_Feed_Writer_Entry::setDateCreated() * Zend_Feed_Writer_Entry::setDateModified() * Zend_Gdata_App_Util::formatTimestamp() * ..etc

Comments

Locations where {{ctype_digits}} is used w/o string cast and the result of my checks:


./library/Zend/Mail/Storage/Maildir.php:364:            if (!ctype_digit($size)) {
## ^-- $size is always string
./library/Zend/Validate/CreditCard.php:255:        if (!ctype_digit($value)) {
## ^-- $value is always string
./library/Zend/Pdf/Parser.php:116:                if (!ctype_digit($nextLexeme)) {
## ^-- $nextLexeme comes from string parser
./library/Zend/Pdf/Parser.php:123:                if (!ctype_digit($refCount)) {
## ^-- $refCount comes from string parser
./library/Zend/Pdf/Parser.php:131:                    if (!ctype_digit($objectOffset)) {
## ^-- $objectOffset is substr'd from a string
./library/Zend/Pdf/Parser.php:151:                    if (!ctype_digit($objectOffset)) {
## ^-- $objectOffset is substr'd from a string
./library/Zend/Pdf/Parser.php:455:        if (!ctype_digit($startXref)) {
## ^-- $startXref comes from a string parser
./library/Zend/Pdf/StringParser.php:500:        if (!ctype_digit($objNum)) { // it's not a reference
## ^-- $objNum comes from a string parser
./library/Zend/Pdf/StringParser.php:506:        if (!ctype_digit($genNum)) { // it's not a reference
## ^-- $genNum comes from a string parser
./library/Zend/Pdf/StringParser.php:560:        if (!ctype_digit($objNum)) {
## ^-- $objNum comes from a string parser
./library/Zend/Pdf/StringParser.php:566:        if (!ctype_digit($genNum)) {
## ^-- $genNum comes from a string parser
./library/Zend/Gdata/App/Util.php:48:        if (ctype_digit($timestamp)) {
## ^-- fixed in r24643
./library/Zend/Feed/Writer/Extension/ITunes/Entry.php:130:        if (!ctype_digit($value)
## ^-- $value is cast to string on L129
./library/Zend/Feed/Writer/Extension/ITunes/Feed.php:193:        if (!ctype_digit($value)
## ^-- $value is cast to string on L192
./library/Zend/Feed/Writer/Entry.php:217:        } elseif (ctype_digit($date)) {
./library/Zend/Feed/Writer/Entry.php:238:        } elseif (ctype_digit($date)) {
## ^-- fixed in r24644 r24645
./library/Zend/Feed/Writer/Deleted.php:131:        } elseif (ctype_digit($date)) {
## ^-- fixed in r24646
./library/Zend/Feed/Writer/Feed/FeedAbstract.php:179:        } elseif (ctype_digit($date)) {
./library/Zend/Feed/Writer/Feed/FeedAbstract.php:200:        } elseif (ctype_digit($date)) {
./library/Zend/Feed/Writer/Feed/FeedAbstract.php:221:        } elseif (ctype_digit($date)) {
## ^-- fixed in r24647

Fixed in trunk r24641, r24642, r24643, r24644, r24645, r24646, r24647 Merged to release-1.11 in r24648