ZF-8598: Zend_Validate_File_IsImage class constant inheritance issue

Issue Type: Bug Created: 2009-12-21T14:08:41.000+0000 Last Updated: 2010-01-26T12:38:12.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Chris Morrell (inxilpro) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate_File

Related issues: - ZF-8111

Attachments: - trunk.diff


The use of class constants in Zend_Validate_File_IsImage is incorrect. See the following code example:

<pre class="highlight">

class Dad
    const HAIR_COLOR = "Brown";
    const EYE_COLOR = "Blue";
    public function getHairColor()
        return self::HAIR_COLOR;
    public function getShirtColor()
        return self::SHIRT_COLOR;

class Son extends Dad
    const HAIR_COLOR = "Red";
    public function getChildHairColor()
        return self::HAIR_COLOR;
    public function getEyeColor()
        return self::EYE_COLOR;

$son = new Son();
echo $son->getHairColor(); // Echoes "Brown"
echo $son->getChildHairColor(); // Echoes "Red"
echo $son->getEyeColor(); // Echoes "Blue"

Because Zend_Validate_File_IsImage redefines constants that are then used in the parent Zend_Validate_File_MimeType class, certain errors have blank messages.

For example, on line 317 of Zend/Validate/File/MimeType:

<pre class="highlight">
if (empty($this->_type)) {
    return $this->_throw($file, self::NOT_DETECTED);

self::NOT_DETECTED refers to 'fileMimeTypeNotDetected' which 'fileIsImageNotDetected' in Zend_Validate_File_IsImage. And because the $_messageTemplates property has been overwritten in Zend_Validate_File_IsImage, the method looks for $this->_messageTemplates['fileMimeTypeNotDetected'] which no longer exists.

The solution would be to remove these constants from the top of Zend_Validate_File_IsImage, as the are already defined in the parent:

<pre class="highlight">
const FALSE_TYPE   = 'fileIsImageFalseType';
const NOT_DETECTED = 'fileIsImageNotDetected';
const NOT_READABLE = 'fileIsImageNotReadable';


Posted by Chris Morrell (inxilpro) on 2009-12-21T14:22:27.000+0000

Attached is a patch to fix this issue. It just removes those constant definitions.

Posted by Thomas Weidner (thomas) on 2009-12-22T14:29:07.000+0000

Unable to reproduce

Wether on 5.2 nor on 5.3 the unittests show that a false message content is thrown.

Posted by Joakim Nygård (jokke) on 2010-01-12T04:08:57.000+0000

The problem is late static binding in PHP 5.2 as explained in this related issue

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.