diff --git a/src/Php/Generator/Utils.php b/src/Php/Generator/Utils.php index 4d2752ee..6aa19d8d 100644 --- a/src/Php/Generator/Utils.php +++ b/src/Php/Generator/Utils.php @@ -18,6 +18,9 @@ trait Utils if (is_int($value) or is_float($value)) { return $value; } + if (is_bool($value)) { + return $value ? 1 : 0; + } if (is_string($value)) { return $this->genCharPtr($value); } else { diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index bfd2911b..6f2e3c4d 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -251,6 +251,9 @@ class Preprocessor extends CompilerBase $nullable = false; } $default = $this->parseParamDefaultValue($param->default); + if ($this->classDef->hasProperty($name)) { + $this->fatalError($param, "Duplicate property `{$name}`"); + } $propertyDef = new PropertyDef($name, $param->flags, $type, $default, $nullable); $this->classDef->properties[$name] = $propertyDef; } @@ -542,7 +545,11 @@ class Preprocessor extends CompilerBase $type = $this->parseTypeDecl($v->type, self::DECL_TYPE_OF_PROPERTY, $class); foreach ($v->props as $prop) { - $propDef = new PropertyDef($this->parseIdentifier($prop->name), $flags, $type); + $propName = $this->parseIdentifier($prop->name); + if ($this->classDef->hasProperty($propName)) { + $this->fatalError($v, "Duplicate property `{$propName}`"); + } + $propDef = new PropertyDef($propName, $flags, $type); if ($prop->default) { $propDef->default = $this->parseIdentifier($prop->default); if ($prop->default->getType() == 'Expr_Array') { diff --git a/src/Php/Translator.php b/src/Php/Translator.php index fbd1a73d..4c9e2a50 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -591,6 +591,8 @@ class Translator extends Preprocessor } } elseif (is_float($value)) { return $value; + } else if (is_bool($value)) { + return $value ? 1 : 0; } elseif (is_string($value)) { return $this->genCharPtr($value); } else { diff --git a/src/gen_stub.php b/src/gen_stub.php index a9239092..9527117c 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -2437,6 +2437,7 @@ class EvaluatedValue // $this->expr has all its PHP constants replaced by C constants $prettyPrinter = new Standard; $expr = $prettyPrinter->prettyPrintExpr($this->expr); + // PHP single-quote to C double-quote string if ($this->type->isString()) { if ( @@ -2449,15 +2450,16 @@ class EvaluatedValue } else { return $this->value; } + } elseif ($this->expr instanceof Expr\ConstFetch) { + return getTranslator()->getConstValue($this->expr->name->toString()); } elseif (!($this->expr instanceof String_)) { - if ($this->expr instanceof Expr\ConstFetch) { - return getTranslator()->getConstValue($this->expr->name->toString()); - } throw new Exception("Expression at line " . $this->expr->getStartLine() . " must be a scalar string"); } $expr = preg_replace("/(^'|'$)/", '"', $expr); - } elseif ($this->type->isInt() or $this->type->isFloat() or $this->expr instanceof Expr\ConstFetch) { + } elseif ($this->type->isInt() or $this->type->isFloat()) { return strval($this->value); + } elseif ($this->type->isBool()) { + return $this->value ? 'true' : 'false'; } return $expr[0] == '"' ? $expr : preg_replace('(\bnull\b)', 'NULL', str_replace('\\', '', $expr)); } diff --git a/tests/aot/object_property/002.phpt b/tests/aot/object_property/002.phpt new file mode 100644 index 00000000..94614e3b --- /dev/null +++ b/tests/aot/object_property/002.phpt @@ -0,0 +1,26 @@ +--TEST-- +default array property +--FILE-- +attr1, $this->attr2, $this->attr3, $this->attr4); + } +} + +function main() { + $obj = new Test; + $obj->bar(); +} +?> +--EXPECT-- +bool(false) +string(5) "hello" +int(1232) +float(3.1415) \ No newline at end of file