Issues

ZF-7804: Invalid property specification if "defaultValue" is NULL

Description

echo new Zend_CodeGenerator_Php_Class(array(
    'name' => 'Foobar',
    'properties' => array(
        new Zend_CodeGenerator_Php_Property(array(
            'name'         => '_dummy',
            'visibility'   => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED,
            'defaultValue' => NULL
        ))
    )
));
class Foobar {
    protected $_dummy = NULL;
}
class Foobar {
    protected $_dummy = ;
}

Comments

Added diff to fix this bug.

This is a duplicate of ZF-6722, its fixed in trunk and 1.9 release branch, which means it will be included in 1.9.3

Why is it duplicate? Zend_CodeGenerator_Php_Parameter is not Zend_CodeGenerator_Php_Property. It is the same problem but located in different classes. And it seems to not be fixed in svn.

Ah ok, well its sort of a duplicate, there is another issue that fixes the parameter thing.

You have to call:


echo new Zend_CodeGenerator_Php_Class(array(
    'name' => 'Foobar',
    'properties' => array(
        new Zend_CodeGenerator_Php_Property(array(
            'name'         => '_dummy',
            'visibility'   => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED,
            'defaultValue' => new ZendCodeGenerator_Php_Property_DefaultValue("NULL")
        ))
    )
));

however the method, setDefaultValue could do that internally also like its done inside the parameter method. I'll add that

Zend_CodeGenerator_Php_Property_DefaultValue has no own constructor. It's only a luck break that it generates "NULL" as result. Following example will also result in "NULL".

echo new Zend_CodeGenerator_Php_Property_DefaultValue(array(
    'foo' => 'bar'
));