Permalink
Browse files

Fix #905: Rework how and when (on unitialize) properties are initialized

  • Loading branch information...
steffen
steffen committed Jun 2, 2015
1 parent 456a45d commit 400efed6e67d2cba2980d874ae1343ed71df746c
Showing with 31 additions and 2 deletions.
  1. +3 −0 Library/ClassDefinition.php
  2. +12 −0 Library/ClassMethod.php
  3. +16 −2 Library/ClassProperty.php
@@ -782,6 +782,9 @@ public function preCompile(CompilationContext $compilationContext)
*/
private function getInternalSignature(ClassMethod $method)
{
if ($method->getName() == 'zephir_init_properties') {
return 'static void ' . $method->getName() . '(zval *this_ptr TSRMLS_DC)';
}
if ($method->getName() == 'zephir_init_static_properties') {
$classDefinition = $method->getClassDefinition();
return 'void ' . $method->getName() . '_' . $classDefinition->getCNamespace() . '_' . $classDefinition->getName() . '(TSRMLS_D)';
@@ -1611,6 +1611,18 @@ public function compile(CompilationContext $compilationContext)
}
}
}
/**
* Set properties of the class, if constructor
*/
if ($this->getName() == '__construct' || ($this->getName() == 'unserialize' && in_array('Serializable', $this->classDefinition->getImplementedInterfaces()))) {
$initMethod = $this->classDefinition->getMethod('zephir_init_properties');
if ($initMethod && $initMethod->getClassDefinition() == $this->classDefinition) {
$codePrinter->increaseLevel();
$codePrinter->output('zephir_init_properties(this_ptr TSRMLS_CC);');
$codePrinter->decreaseLevel();
}
}
/**
* Compile the block of statements if any
@@ -248,11 +248,25 @@ public function compile(CompilationContext $compilationContext)
case 'array':
case 'empty-array':
$methodName = '__construct';
$visibility = array('public');
if ($this->isStatic()) {
$methodName = 'zephir_init_static_properties';
$visibility = array('internal');
} else {
$methodName = 'zephir_init_properties';
$visibility = array('internal');
/* Make sure a constructor exists, so that properties are initialized */
$method = $compilationContext->classDefinition->getMethod('__construct');
if (!$method || $method->getClassDefinition() != $this->classDefinition) {
$this->classDefinition->addMethod(new ClassMethod(
$compilationContext->classDefinition,
array('public'),
'__construct',
null,
null
), null);
}
}
$constructParentMethod = null;

0 comments on commit 400efed

Please sign in to comment.