diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index da9c7d26..9aed496f 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -4120,6 +4120,12 @@ class CompilerBase extends \PhpAot\Core\Translator } $this->fatalError($node, 'Cannot convert float expression to Decimal, use a literal value or string instead'); } + if ($fromType === self::TYPE_STR) { + if ($node instanceof Node\Scalar\String_) { + return 'php::newDecimal(' . $this->getLiteralString($node->value) . ')'; + } + return 'php::newDecimal(php::toString(' . $this->trimBrackets($expr) . '))'; + } if ($fromType === self::TYPE_INT) { return 'php::newDecimal(php::toString(' . $this->trimBrackets($expr) . '))'; } @@ -4137,6 +4143,9 @@ class CompilerBase extends \PhpAot\Core\Translator if ($fromType === self::TYPE_FLOAT) { $this->fatalError(null, 'Cannot convert float to BigInt, use string or int instead'); } + if ($fromType === self::TYPE_STR) { + return 'php::newBigInt(php::toString(' . $this->trimBrackets($expr) . '))'; + } return $expr; } @@ -4148,6 +4157,9 @@ class CompilerBase extends \PhpAot\Core\Translator if ($fromType === self::TYPE_FLOAT) { return 'php::newBigFloat(' . $this->trimBrackets($expr) . ')'; } + if ($fromType === self::TYPE_STR) { + return 'php::newBigFloat(php::toString(' . $this->trimBrackets($expr) . '))'; + } if ($fromType === self::TYPE_BIGINT) { return 'php::BigFloat::newInstance(php::BigInt::toString(' . $this->trimBrackets($expr) . '))'; } diff --git a/tests/aot/var_convert/003.phpt b/tests/aot/var_convert/003.phpt new file mode 100644 index 00000000..73507e93 --- /dev/null +++ b/tests/aot/var_convert/003.phpt @@ -0,0 +1,13 @@ +--TEST-- +var convert chained on array element +--FILE-- +toDecimal(); + $r = $v + '0.2'; + echo $r; +} +?> +--EXPECT-- +0.3