ZF-12084: isSourceDirty is not set to true when setting a new default value

Description

This issue has taken me a few hours to understand, and I cannot understand that this is intented behaviour.

When modifying an existing property of Zend_CodeGenerator_Php_Class, and setting a new default value. isSourceDirty is still false, so that generate() will only return null.


<?php
class TestClass{
 protected $value = array();
}

<?php
$generator = Zend_CodeGenerator_Php_Class::fromReflection ( new Zend_Reflection_Class ( 'TestClass' ) );
$property = $generator->getProperty ( 'value' );

$newValues = array(1,2,3,4,5,6,7);
$property->setDefaultValue ( $newValues );

var_dump ( $metadataProperty->isSourceDirty () ); //will return false
var_dump ( $metadataProperty->generate() ); //therefore this will return null and not code for the new class

The workaround is fairly easy, but I assume this is not the correct behaviour and should be handled inside ZF?


<?php
$generator = Zend_CodeGenerator_Php_Class::fromReflection ( new Zend_Reflection_Class ( 'TestClass' ) );
$property = $generator->getProperty ( 'value' );

$newValues = array(1,2,3,4,5,6,7);

if ($property->getDefaultValue () != $newValues) {
  $property->setSourceDirty ( true );           
  $property->setDefaultValue ( $newValues );
}

var_dump ( $metadataProperty->isSourceDirty () ); //will return true
var_dump ( $metadataProperty->generate() ); //this returns code for the new class as it should

Comments

A small bug in the workaround, it should be:

if ($property->getDefaultValue ()->getValue () != $newValues)