Issues

ZF-7268: Zend_CodeGenerator_Php_Property_DefaultValue shouldn't include semicolon

Issue Type: Improvement Created: 2009-07-14T10:50:14.000+0000 Last Updated: 2011-03-23T20:52:37.000+0000 Status: Resolved Fix version(s): Reporter: Søren Haagerup (shaagerup) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_CodeGenerator

Related issues: Attachments:

Description

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:

<pre class="highlight">
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();
$temp->setValue($elementsArray);

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


echo $class->generate();

results in

<pre class="highlight">
class SamleClass
{

    public function __construct()
    {
        $this->addElements(array(
                '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

<pre class="highlight"> 
$temp = new Zend_CodeGenerator_Php_Property_DefaultValue();
$temp->setValue($elementsArray);

could be simplified to

<pre class="highlight">
$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 :-).

Comments

Posted by Matthew Weier O'Phinney (matthew) on 2011-03-23T20:52:26.000+0000

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).

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts