ZF-8598: Zend_Validate_File_IsImage class constant inheritance issue
Description
The use of class constants in Zend_Validate_File_IsImage is incorrect. See the following code example:
<?php
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:
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:
const FALSE_TYPE = 'fileIsImageFalseType';
const NOT_DETECTED = 'fileIsImageNotDetected';
const NOT_READABLE = 'fileIsImageNotReadable';
Comments
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