ZF-7268: Zend_CodeGenerator_Php_Property_DefaultValue shouldn't include semicolon


When writing Code Generation code, I have found it useful to use Zend_CodeGenerator_Php_Property_DefaultValue to build parts of function body code. For example:

require_once 'Zend/CodeGenerator/Php/Class.php';
require_once 'Zend/CodeGenerator/Php/Property/DefaultValue.php';

$elementsArray = array('test1' => 'Description1', 'test2' => 'Description2');

$class = new Zend_CodeGenerator_Php_Class();
$class->setName('SamleClass' );

$temp = new Zend_CodeGenerator_Php_Property_DefaultValue();

$cbody = '$this->addElements(' .$temp->generate(). ');';
    'name'         => '__construct',
    'visibility'   => 'public',
    'body' => $cbody

echo $class->generate();

results in

class SamleClass

    public function __construct()
                'test1' => 'Description1',
                'test2' => 'Description2'


It could be nice if the semicolon wasn't part of Zend_CodeGenerator_Php_Property_DefaultValue in scenarios like this.

A similar suggestion: If

$temp = new Zend_CodeGenerator_Php_Property_DefaultValue();

could be simplified to

$temp = new Zend_CodeGenerator_Php_Property_DefaultValue($elementsArray);

it would be nice too.

Let me know if there are better ways to accomplish what I'm trying to :-).


Typically, you shouldn't use CodeGenerator for the body of a method. If you do, Php_Property_DefaultValue is not the appropriate class to use here anyways -- that class is intended for code generation of a class property, not inline-code (Php_Value would be the more appropriate case here).