ZF-9440: Zend_CodeGenerator_Php_Property_DefaultValue fails to render multidimensional array with TYPE_ARRAY set
Description
When using Zend_CodeGenerator_Php_Property_DefaultValue and setting a multidimensional array as the value and setting Zend_CodeGenerator_Php_Property_DefaultValue::TYPE_ARRAY as type i get:
Fatal error: Call to a member function setArrayDepth() on a non-object in /home/developer/projects/zftrunk/library/Zend/CodeGenerator/Php/Property/DefaultValue.php on line 294
Based on this i wrote an additional unittest to show this behavior
public function testPropertyDefaultValueCanHandleMultidimensionalArray()
{
$propDefaultValue = new Zend_CodeGenerator_Php_Property_DefaultValue();
$propDefaultValue->setValue(array('foo' => array('bar' => 'baz'), 'bar' => array('foo' => 'baz')));
$expected = 'array(
\'foo\' => array(\'bar\' => \'baz\'),
\'bar\' => array(\'foo\' => \'baz\')
);';
$this->assertEquals($expected, $propDefaultValue->generate());
$propDefaultValue->setType(Zend_CodeGenerator_Php_Property_DefaultValue::TYPE_ARRAY);
$this->assertEquals($expected, $propDefaultValue->generate());
}
The first assertion works fine as TYPE_AUTO is used and a special handling for TYPE_ARRAY is then activated. (DefaultValue.php line 243) The second assertion dies with mentioned error.
Comments
Posted by Michael Prüfer (m.pruefer) on 2010-03-17T01:49:57.000+0000
I made a patch which resolves the problem for me.