Zend Framework

Zend_Validate_File_IsImage class constant inheritance issue

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major 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';

Issue Links

Activity

Hide
Chris Morrell added a comment -

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

Show
Chris Morrell added a comment - Attached is a patch to fix this issue. It just removes those constant definitions.
Hide
Thomas Weidner added a comment -

Unable to reproduce

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

Show
Thomas Weidner added a comment - Unable to reproduce Wether on 5.2 nor on 5.3 the unittests show that a false message content is thrown.
Hide
Joakim Nygård added a comment -

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

Show
Joakim Nygård added a comment - The problem is late static binding in PHP 5.2 as explained in this related issue

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: