Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.9.6
-
Fix Version/s: 1.10.0
-
Component/s: Zend_Validate_File
-
Labels:None
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';
Attached is a patch to fix this issue. It just removes those constant definitions.