Permalink
Browse files

Fix #537: Make sure class properties are initialized in the right order

  • Loading branch information...
steffen
steffen committed Jun 1, 2015
1 parent 5296015 commit 9448a9c89955213ca772b08eb37e2db4862b14a2
@@ -255,7 +255,17 @@ public function compile(CompilationContext $compilationContext)
$visibility = array('internal');
}
$constructParentMethod = null;
$constructMethod = $compilationContext->classDefinition->getMethod($methodName);
/**
* Make sure we do not steal the construct method of the parent,
* but initialize our own with the inherited statements to ensure
* valid property initialization
*/
if ($constructMethod && $constructMethod->getClassDefinition() != $this->classDefinition) {
$constructParentMethod = $constructMethod;
$constructMethod = null;
}
if ($constructMethod) {
$statementsBlock = $constructMethod->getStatementsBlock();
if ($statementsBlock) {
@@ -292,9 +302,12 @@ public function compile(CompilationContext $compilationContext)
$compilationContext->classDefinition->getEventsManager()->dispatch('setMethod', array($constructMethod));
}
} else {
$statementsBlock = new StatementsBlock(array(
$this->getLetStatement()->get()
));
$statements = array();
if ($constructParentMethod) {
$statements = $constructParentMethod->getStatementsBlock()->getStatements();
}
$statements[] = $this->getLetStatement()->get();
$statementsBlock = new StatementsBlock($statements);
$compilationContext->classDefinition->getEventsManager()->dispatch('setMethod', array(new ClassMethod(
$compilationContext->classDefinition,
@@ -4,4 +4,6 @@ namespace Test\Properties;
class ExtendsPublicProperties extends PublicProperties
{
public testPropertyFromClassNameConstantValue = PublicProperties::TEST_CONST;
}
protected someGetterSetterArray = ["holy"];
}
@@ -67,6 +67,8 @@ class PublicProperties
"danger": ["class": "alert alert-danger"]
];
protected someGetterSetterArray = [] { set, get };
public testPropertyFromSelfConstantValue = self::TEST_CONST;
public testPropertyFromClassNameConstantValue = PublicProperties::TEST_CONST;
@@ -20,6 +20,7 @@
namespace Extension\Properties;
use Test\Properties\PublicProperties;
use Test\Properties\ExtendsPublicProperties;
class PublicPropertiesTest extends \PHPUnit_Framework_TestCase
{
@@ -44,4 +45,13 @@ public function test394Issue()
$t = new PublicProperties();
$this->assertTrue($t->test394Issue());
}
/**
* @link https://github.com/phalcon/zephir/issues/537
*/
public function test537Issue()
{
$t = new ExtendsPublicProperties();
$this->assertEquals($t->getSomeGetterSetterArray(), array("holy"));
}
}

0 comments on commit 9448a9c

Please sign in to comment.