diff --git a/CHANGELOG.md b/CHANGELOG.md
index b445eceb20..2048c95c94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org).
## [Unreleased]
+## [0.14.0-beta.1] - 2021-08-06
+### Fixed
+- Fixed nullable dynamic argument definition [#2245](https://github.com/zephir-lang/zephir/issues/2245)
+
+### Changed
+- Changed detection of external class entries [#2213](https://github.com/zephir-lang/zephir/issues/2213)
## [0.13.5] - 2021-05-09
### Fixed
@@ -520,7 +526,8 @@ and this project adheres to [Semantic Versioning](http://semver.org).
[#1524](https://github.com/zephir-lang/zephir/issues/1524)
-[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.13.5...HEAD
+[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.1...HEAD
+[0.14.0-beta.1]: https://github.com/zephir-lang/zephir/compare/0.13.5...0.14.0-beta.1
[0.13.5]: https://github.com/zephir-lang/zephir/compare/0.13.4...0.13.5
[0.13.4]: https://github.com/zephir-lang/zephir/compare/0.13.3...0.13.4
[0.13.3]: https://github.com/zephir-lang/zephir/compare/0.13.2...0.13.3
diff --git a/Library/Call.php b/Library/Call.php
index c443c7e70d..19252a563a 100644
--- a/Library/Call.php
+++ b/Library/Call.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir;
use Zephir\Detectors\ReadDetector;
@@ -24,27 +26,54 @@ class Call
/**
* Call expression.
*
- * @var Expression
+ * @var Expression|null
*/
- protected $expression;
+ protected ?Expression $expression = null;
- protected $mustInit;
+ /**
+ * @var bool
+ */
+ protected bool $mustInit = false;
- protected $symbolVariable;
+ /**
+ * @var Variable|null
+ */
+ protected ?Variable $symbolVariable = null;
- protected $isExpecting = false;
+ /**
+ * @var bool
+ */
+ protected bool $isExpecting = false;
- protected $resolvedParams;
+ /**
+ * @var array
+ */
+ protected array $resolvedParams = [];
- protected $reflection;
+ /**
+ * @var mixed|null
+ */
+ protected $reflection = null;
- protected $resolvedTypes = [];
+ /**
+ * @var array
+ */
+ protected array $resolvedTypes = [];
- protected $resolvedDynamicTypes = [];
+ /**
+ * @var array
+ */
+ protected array $resolvedDynamicTypes = [];
- protected $temporalVariables = [];
+ /**
+ * @var array
+ */
+ protected array $temporalVariables = [];
- protected $mustCheckForCopy = [];
+ /**
+ * @var array
+ */
+ protected array $mustCheckForCopy = [];
/**
* Processes the symbol variable that will be used to return
@@ -60,7 +89,6 @@ public function processExpectedReturn(CompilationContext $compilationContext)
/**
* Create temporary variable if needed.
*/
- $mustInit = false;
$symbolVariable = null;
$isExpecting = $expr->isExpectingReturn();
if ($isExpecting) {
@@ -74,14 +102,13 @@ public function processExpectedReturn(CompilationContext $compilationContext)
$expression
);
} else {
- $mustInit = true;
+ $this->mustInit = true;
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
}
- $this->mustInit = $mustInit;
$this->symbolVariable = $symbolVariable;
$this->isExpecting = $isExpecting;
}
@@ -92,7 +119,7 @@ public function processExpectedReturn(CompilationContext $compilationContext)
*
* @param CompilationContext $compilationContext
*/
- public function processExpectedObservedReturn(CompilationContext $compilationContext)
+ public function processExpectedObservedReturn(CompilationContext $compilationContext): void
{
$expr = $this->expression;
$expression = $expr->getExpression();
@@ -122,48 +149,12 @@ public function processExpectedObservedReturn(CompilationContext $compilationCon
$this->isExpecting = $isExpecting;
}
- /**
- * Processes the symbol variable that will be used to return
- * the result of the symbol call. If a temporal variable is used
- * as returned value only the body is freed between calls.
- *
- * @param CompilationContext $compilationContext
- */
- public function processExpectedComplexLiteralReturn(CompilationContext $compilationContext)
- {
- $expr = $this->expression;
- $expression = $expr->getExpression();
-
- /**
- * Create temporary variable if needed.
- */
- $mustInit = false;
- $isExpecting = $expr->isExpectingReturn();
- if ($isExpecting) {
- $symbolVariable = $expr->getExpectingVariable();
- if (\is_object($symbolVariable)) {
- $readDetector = new ReadDetector();
- if ($readDetector->detect($symbolVariable->getName(), $expression)) {
- $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression);
- } else {
- $mustInit = true;
- }
- } else {
- $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression);
- }
- }
-
- $this->mustInit = $mustInit;
- $this->symbolVariable = $symbolVariable;
- $this->isExpecting = $isExpecting;
- }
-
/**
* Check if an external expression is expecting the call return a value.
*
* @return bool
*/
- public function isExpectingReturn()
+ public function isExpectingReturn(): bool
{
return $this->isExpecting;
}
@@ -173,7 +164,7 @@ public function isExpectingReturn()
*
* @return bool
*/
- public function mustInitSymbolVariable()
+ public function mustInitSymbolVariable(): bool
{
return $this->mustInit;
}
@@ -181,12 +172,12 @@ public function mustInitSymbolVariable()
/**
* Returns the symbol variable that must be returned by the call.
*
- * @param bool $useTemp
+ * @param bool $useTemp
* @param CompilationContext|null $compilationContext
*
- * @return Variable
+ * @return Variable|null
*/
- public function getSymbolVariable($useTemp = false, CompilationContext $compilationContext = null)
+ public function getSymbolVariable(bool $useTemp = false, CompilationContext $compilationContext = null): ?Variable
{
$symbolVariable = $this->symbolVariable;
@@ -200,17 +191,15 @@ public function getSymbolVariable($useTemp = false, CompilationContext $compilat
/**
* Resolves parameters.
*
- * @param array $parameters
+ * @param array $parameters
* @param CompilationContext $compilationContext
- * @param array $expression
- * @param bool $readOnly
+ * @param array $expression
+ * @param bool $readOnly
*
- * @throws CompilerException
- *
- * @return array|CompiledExpression[]|null
- * @return array
+ * @return CompiledExpression[]|null
+ * @throws Exception
*/
- public function getResolvedParamsAsExpr($parameters, CompilationContext $compilationContext, $expression, $readOnly = false)
+ public function getResolvedParamsAsExpr(array $parameters, CompilationContext $compilationContext, array $expression, bool $readOnly = false): ?array
{
if (!$this->resolvedParams) {
$hasParametersByName = false;
@@ -221,7 +210,7 @@ public function getResolvedParamsAsExpr($parameters, CompilationContext $compila
}
}
- /*
+ /**
* All parameters must be passed by name
*/
if ($hasParametersByName) {
@@ -298,16 +287,15 @@ public function getResolvedParamsAsExpr($parameters, CompilationContext $compila
* Resolve parameters getting aware that the target function/method could retain or change
* the parameters.
*
- * @param array $parameters
+ * @param array $parameters
* @param CompilationContext $compilationContext
- * @param array $expression
- * @param array $calleeDefinition
- *
- * @throws CompilerException
+ * @param array $expression
+ * @param null $calleeDefinition
*
* @return array
+ * @throws Exception
*/
- public function getResolvedParams($parameters, CompilationContext $compilationContext, array $expression, $calleeDefinition = null)
+ public function getResolvedParams(array $parameters, CompilationContext $compilationContext, array $expression, $calleeDefinition = null): array
{
$codePrinter = $compilationContext->codePrinter;
$exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression);
@@ -319,7 +307,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo
$readOnlyParameters = [];
if (\is_object($calleeDefinition)) {
if ($calleeDefinition instanceof ClassMethod) {
- if ($calleeDefinition->isFinal() || $calleeDefinition->isPrivate() || $calleeDefinition->isInternal() || $compilationContext->currentMethod == $calleeDefinition) {
+ if ($calleeDefinition->isFinal() || $calleeDefinition->isPrivate() || $calleeDefinition->isInternal() || $compilationContext->currentMethod === $calleeDefinition) {
foreach ($calleeDefinition->getParameters() as $position => $parameter) {
if (isset($parameter['data-type'])) {
switch ($parameter['data-type']) {
@@ -344,7 +332,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo
$types = [];
$dynamicTypes = [];
$mustCheck = [];
- foreach ($exprParams as $position => $compiledExpression) {
+ foreach ($exprParams as $compiledExpression) {
$expression = $compiledExpression->getOriginal();
switch ($compiledExpression->getType()) {
case 'null':
@@ -399,8 +387,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo
$compilationContext->backend->assignString(
$parameterVariable,
add_slashes($compiledExpression->getCode()),
- $compilationContext,
- true
+ $compilationContext
);
$this->temporalVariables[] = $parameterVariable;
@@ -499,15 +486,14 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo
/**
* Resolve parameters using zvals in the stack and without allocating memory for constants.
*
- * @param array $parameters
+ * @param array $parameters
* @param CompilationContext $compilationContext
- * @param array $expression
- *
- * @throws CompilerException
+ * @param array $expression
*
* @return array
+ * @throws Exception
*/
- public function getReadOnlyResolvedParams($parameters, CompilationContext $compilationContext, array $expression)
+ public function getReadOnlyResolvedParams(array $parameters, CompilationContext $compilationContext, array $expression): array
{
$codePrinter = $compilationContext->codePrinter;
$exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression, true);
@@ -550,8 +536,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi
$compilationContext->backend->assignString(
$parameterVariable,
add_slashes($compiledExpression->getCode()),
- $compilationContext,
- true
+ $compilationContext
);
$this->temporalVariables[] = $parameterVariable;
@@ -681,7 +666,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi
*
* @param CompilationContext $compilationContext
*/
- public function addCallStatusFlag(CompilationContext $compilationContext)
+ public function addCallStatusFlag(CompilationContext $compilationContext): void
{
if (!$compilationContext->symbolTable->hasVariable('ZEPHIR_LAST_CALL_STATUS')) {
$callStatus = new Variable('int', 'ZEPHIR_LAST_CALL_STATUS', $compilationContext->branchManager->getCurrentBranch());
@@ -697,7 +682,7 @@ public function addCallStatusFlag(CompilationContext $compilationContext)
*
* @param CompilationContext $compilationContext
*/
- public function addCallStatusOrJump(CompilationContext $compilationContext)
+ public function addCallStatusOrJump(CompilationContext $compilationContext): void
{
$compilationContext->headersManager->add('kernel/fcall');
if ($compilationContext->insideTryCatch) {
@@ -716,7 +701,7 @@ public function addCallStatusOrJump(CompilationContext $compilationContext)
*
* @param CompilationContext $compilationContext
*/
- public function checkTempParameters(CompilationContext $compilationContext)
+ public function checkTempParameters(CompilationContext $compilationContext): void
{
$compilationContext->headersManager->add('kernel/fcall');
foreach ($this->getMustCheckForCopyVariables() as $checkVariable) {
@@ -729,7 +714,7 @@ public function checkTempParameters(CompilationContext $compilationContext)
*
* @return array
*/
- public function getResolvedTypes()
+ public function getResolvedTypes(): array
{
return $this->resolvedTypes;
}
@@ -739,7 +724,7 @@ public function getResolvedTypes()
*
* @return array
*/
- public function getResolvedDynamicTypes()
+ public function getResolvedDynamicTypes(): array
{
return $this->resolvedDynamicTypes;
}
@@ -749,7 +734,7 @@ public function getResolvedDynamicTypes()
*
* @return Variable[]
*/
- public function getTemporalVariables()
+ public function getTemporalVariables(): array
{
return $this->temporalVariables;
}
@@ -759,7 +744,7 @@ public function getTemporalVariables()
*
* @return array
*/
- public function getMustCheckForCopyVariables()
+ public function getMustCheckForCopyVariables(): array
{
return $this->mustCheckForCopy;
}
diff --git a/Library/ClassConstant.php b/Library/ClassConstant.php
index bae66374b9..376d50aa32 100644
--- a/Library/ClassConstant.php
+++ b/Library/ClassConstant.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir;
use Zephir\Exception\CompilerException;
@@ -25,26 +27,26 @@ class ClassConstant
/**
* @var string
*/
- protected $name;
+ protected string $name;
/**
* @var array
*/
- protected $value = [];
+ protected array $value = [];
/**
- * @var string
+ * @var string|null
*/
- protected $docblock;
+ protected ?string $docblock = null;
/**
* ClassConstant constructor.
*
* @param string $name
* @param array $value
- * @param string $docBlock
+ * @param string|null $docBlock
*/
- public function __construct($name, array $value, $docBlock)
+ public function __construct(string $name, array $value, ?string $docBlock = null)
{
$this->name = $name;
$this->value = $value;
@@ -56,7 +58,7 @@ public function __construct($name, array $value, $docBlock)
*
* @return string
*/
- public function getName()
+ public function getName(): string
{
return $this->name;
}
@@ -68,7 +70,7 @@ public function getName()
*
* @return array
*/
- public function getValue()
+ public function getValue(): array
{
return $this->value;
}
@@ -78,7 +80,7 @@ public function getValue()
*
* @return string
*/
- public function getValueType()
+ public function getValueType(): string
{
return $this->value['type'];
}
@@ -90,19 +92,15 @@ public function getValueType()
*/
public function getValueValue()
{
- if (isset($this->value['value'])) {
- return $this->value['value'];
- }
-
- return false;
+ return $this->value['value'] ?? false;
}
/**
* Returns the docblock related to the constant.
*
- * @return string
+ * @return string|null
*/
- public function getDocBlock()
+ public function getDocBlock(): ?string
{
return $this->docblock;
}
@@ -112,7 +110,7 @@ public function getDocBlock()
*
* @return string
*/
- public function getType()
+ public function getType(): string
{
return $this->value['type'];
}
@@ -126,7 +124,7 @@ public function getType()
*/
public function processValue(CompilationContext $compilationContext)
{
- if ('constant' == $this->value['type']) {
+ if ('constant' === $this->value['type']) {
$constant = new Constants();
$compiledExpression = $constant->compile($this->value, $compilationContext);
@@ -138,7 +136,7 @@ public function processValue(CompilationContext $compilationContext)
return;
}
- if ('static-constant-access' == $this->value['type']) {
+ if ('static-constant-access' === $this->value['type']) {
$staticConstantAccess = new StaticConstantAccess();
$compiledExpression = $staticConstantAccess->compile($this->value, $compilationContext);
@@ -146,8 +144,6 @@ public function processValue(CompilationContext $compilationContext)
'type' => $compiledExpression->getType(),
'value' => $compiledExpression->getCode(),
];
-
- return;
}
}
@@ -159,16 +155,16 @@ public function processValue(CompilationContext $compilationContext)
* @throws CompilerException
* @throws Exception
*/
- public function compile(CompilationContext $compilationContext)
+ public function compile(CompilationContext $compilationContext): void
{
$this->processValue($compilationContext);
- $constanValue = isset($this->value['value']) ? $this->value['value'] : null;
+ $constantValue = $this->value['value'] ?? null;
$compilationContext->backend->declareConstant(
$this->value['type'],
$this->getName(),
- $constanValue,
+ $constantValue,
$compilationContext
);
}
diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php
index 591ad82e36..ad421be22d 100644
--- a/Library/ClassDefinition.php
+++ b/Library/ClassDefinition.php
@@ -15,6 +15,7 @@
use ReflectionClass;
use ReflectionException;
+use Zephir\Classes\Entry;
use Zephir\Documentation\Docblock;
use Zephir\Documentation\DocblockParser;
use Zephir\Exception\CompilerException;
@@ -789,7 +790,7 @@ public function getMethod(string $methodName, bool $checkExtends = true): ?Class
/**
* Set a method and its body.
*
- * @param $methodName
+ * @param string $methodName
* @param ClassMethod $method
*/
public function setMethod(string $methodName, ClassMethod $method): void
@@ -1121,15 +1122,14 @@ public function compile(CompilationContext $compilationContext): void
if ($classExtendsDefinition instanceof self && !$classExtendsDefinition->isBundled()) {
$classEntry = $classExtendsDefinition->getClassEntry($compilationContext);
} else {
- $classEntry = $this->getClassEntryByClassName($classExtendsDefinition->getName(), $compilationContext);
+ $className = method_exists($classExtendsDefinition, 'getCompleteName') ? $classExtendsDefinition->getCompleteName() : $classExtendsDefinition->getName();
+ $classEntry = (new Entry($className, $compilationContext))->get();
}
if (self::TYPE_CLASS === $this->getType()) {
$codePrinter->output('ZEPHIR_REGISTER_CLASS_EX('.$this->getNCNamespace().', '.$this->getName().', '.$namespace.', '.strtolower($this->getSCName($namespace)).', '.$classEntry.', '.$methodEntry.', '.$flags.');');
- $codePrinter->outputBlankLine();
} else {
$codePrinter->output('ZEPHIR_REGISTER_INTERFACE_EX('.$this->getNCNamespace().', '.$this->getName().', '.$namespace.', '.strtolower($this->getSCName($namespace)).', '.$classEntry.', '.$methodEntry.');');
- $codePrinter->outputBlankLine();
}
} else {
if (self::TYPE_CLASS === $this->getType()) {
@@ -1137,16 +1137,17 @@ public function compile(CompilationContext $compilationContext): void
} else {
$codePrinter->output('ZEPHIR_REGISTER_INTERFACE('.$this->getNCNamespace().', '.$this->getName().', '.$namespace.', '.strtolower($this->getSCName($namespace)).', '.$methodEntry.');');
}
- $codePrinter->outputBlankLine();
}
+ $codePrinter->outputBlankLine();
+
/**
* Compile properties.
*/
foreach ($this->getProperties() as $property) {
$docBlock = $property->getDocBlock();
if ($docBlock) {
- $codePrinter->outputDocBlock($docBlock, true);
+ $codePrinter->outputDocBlock($docBlock);
}
$property->compile($compilationContext);
@@ -1164,7 +1165,7 @@ public function compile(CompilationContext $compilationContext): void
foreach ($this->getConstants() as $constant) {
$docBlock = $constant->getDocBlock();
if ($docBlock) {
- $codePrinter->outputDocBlock($docBlock, true);
+ $codePrinter->outputDocBlock($docBlock);
}
$constant->compile($compilationContext);
@@ -1184,16 +1185,14 @@ public function compile(CompilationContext $compilationContext): void
/**
* Try to find the interface.
*/
- $classEntry = false;
+ $classEntry = null;
if ($compiler->isInterface($interface)) {
$classInterfaceDefinition = $compiler->getClassDefinition($interface);
$classEntry = $classInterfaceDefinition->getClassEntry($compilationContext);
- } else {
- if ($compiler->isBundledInterface($interface)) {
- $classInterfaceDefinition = $compiler->getInternalClassDefinition($interface);
- $classEntry = $this->getClassEntryByClassName($classInterfaceDefinition->getName(), $compilationContext);
- }
+ } elseif ($compiler->isBundledInterface($interface)) {
+ $classInterfaceDefinition = $compiler->getInternalClassDefinition($interface);
+ $classEntry = (new Entry('\\'.$classInterfaceDefinition->getName(), $compilationContext))->get();
}
if (!$classEntry) {
@@ -1294,11 +1293,7 @@ public function compile(CompilationContext $compilationContext): void
* Check whether classes must be exported.
*/
$exportClasses = $compilationContext->config->get('export-classes', 'extra');
- if ($exportClasses) {
- $exportAPI = 'extern ZEPHIR_API';
- } else {
- $exportAPI = 'extern';
- }
+ $exportAPI = $exportClasses ? 'extern ZEPHIR_API' : 'extern';
/**
* Create a code printer for the header file.
@@ -1466,504 +1461,6 @@ public function setAliasManager(AliasManager $aliasManager): void
$this->aliasManager = $aliasManager;
}
- /**
- * Convert Class/Interface name to C ClassEntry.
- *
- * @param string $className
- * @param CompilationContext $compilationContext
- * @param bool $check
- * @return string
- * @throws CompilerException
- */
- public function getClassEntryByClassName(
- string $className,
- CompilationContext $compilationContext,
- bool $check = true
- ): string {
- $this->compiler = $compilationContext->compiler;
-
- /**
- * Special treatment for Reflection in 8.0.
- * Because in PHP 7.4 param arg info is lighter,
- * but also incomplete.
- *
- * TODO: Leave for future, maybe PHP code devs will make "reflection" ext public...
- */
- /*if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
- switch (strtolower($className)) {
- case 'reflector':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflector_ptr';
- break;
- case 'reflectionexception':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_exception_ptr';
- break;
- case 'reflection':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_ptr';
- break;
- case 'reflectionfunctionabstract':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_function_abstract_ptr';
- break;
- case 'reflectionfunction':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_function_ptr';
- break;
- case 'reflectionparameter':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_parameter_ptr';
- break;
- case 'reflectionclass':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_class_ptr';
- break;
- case 'reflectionobject':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_object_ptr';
- break;
- case 'reflectionmethod':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_method_ptr';
- break;
- case 'reflectionproperty':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_property_ptr';
- break;
- case 'reflectionextension':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_extension_ptr';
- break;
- case 'reflectionzendextension':
- $compilationContext->headersManager->add('ext/reflection/php_reflection');
- $classEntry = 'reflection_zend_extension_ptr';
- break;
- default:
- $classEntry = null;
- break;
- }
-
- if ($classEntry !== null) {
- return $classEntry;
- }
- }*/
-
- switch (strtolower($className)) {
- /**
- * Zend exceptions
- */
- case 'throwable':
- $classEntry = 'zend_ce_throwable';
- break;
-
- case 'exception':
- $classEntry = 'zend_ce_exception';
- break;
-
- case 'errorexception':
- $classEntry = 'zend_ce_error_exception';
- break;
-
- case 'error':
- $classEntry = 'zend_ce_error';
- break;
-
- case 'compileerror':
- $classEntry = 'zend_ce_compile_error';
- break;
-
- case 'parseerror':
- $classEntry = 'zend_ce_parse_error';
- break;
-
- case 'typeerror':
- $classEntry = 'zend_ce_type_error';
- break;
-
- case 'argumentcounterror':
- $classEntry = 'zend_ce_argument_count_error';
- break;
-
- case 'valueerror':
- $classEntry = 'zend_ce_value_error';
- break;
-
- case 'arithmeticerror':
- $classEntry = 'zend_ce_arithmetic_error';
- break;
-
- case 'divisionbyzeroerror':
- $classEntry = 'zend_ce_division_by_zero_error';
- break;
-
- case 'unhandledmatcherror':
- $classEntry = 'zend_ce_unhandled_match_error';
- break;
-
- /**
- * Zend interfaces (Zend/zend_interfaces.h)
- */
- case 'traversable':
- $classEntry = 'zend_ce_traversable';
- break;
-
- case 'aggregate':
- $classEntry = 'zend_ce_aggregate';
- break;
-
- case 'iterator':
- $classEntry = 'zend_ce_iterator';
- break;
-
- case 'arrayaccess':
- $classEntry = 'zend_ce_arrayaccess';
- break;
-
- case 'serializable':
- $classEntry = 'zend_ce_serializable';
- break;
-
- case 'countable':
- $classEntry = 'zend_ce_countable';
- break;
-
- case 'stringable':
- $classEntry = 'zend_ce_stringable';
- break;
-
- /**
- * SPL Exceptions
- */
- case 'logicexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_LogicException';
- break;
-
- case 'badfunctioncallexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_BadFunctionCallException';
- break;
-
- case 'badmethodcallexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_BadMethodCallException';
- break;
-
- case 'domainexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_DomainException';
- break;
-
- case 'invalidargumentexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_InvalidArgumentException';
- break;
-
- case 'lengthexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_LengthException';
- break;
-
- case 'outofrangeexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_OutOfRangeException';
- break;
-
- case 'runtimeexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_RuntimeException';
- break;
-
- case 'outofboundsexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_OutOfBoundsException';
- break;
-
- case 'overflowexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_OverflowException';
- break;
-
- case 'rangeexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_RangeException';
- break;
-
- case 'underflowexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_UnderflowException';
- break;
-
- case 'unexpectedvalueexception':
- $compilationContext->headersManager->add('ext/spl/spl_exceptions');
- $classEntry = 'spl_ce_UnexpectedValueException';
- break;
-
- /**
- * SPL Iterators Interfaces (spl/spl_iterators.h)
- */
- case 'recursiveiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RecursiveIterator';
- break;
-
- case 'recursiveiteratoriterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RecursiveIteratorIterator';
- break;
-
- case 'recursivetreeiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RecursiveTreeIterator';
- break;
-
- case 'filteriterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_FilterIterator';
- break;
-
- case 'recursivefilteriterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RecursiveFilterIterator';
- break;
-
- case 'parentiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_ParentIterator';
- break;
-
- case 'seekableiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_SeekableIterator';
- break;
-
- case 'limititerator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_LimitIterator';
- break;
-
- case 'cachingiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_CachingIterator';
- break;
-
- case 'recursivecachingiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RecursiveCachingIterator';
- break;
-
- case 'outeriterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_OuterIterator';
- break;
-
- case 'iteratoriterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_IteratorIterator';
- break;
-
- case 'norewinditerator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_NoRewindIterator';
- break;
-
- case 'infiniteiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_InfiniteIterator';
- break;
-
- case 'emptyiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_EmptyIterator';
- break;
-
- case 'appenditerator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_AppendIterator';
- break;
-
- case 'regexiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RegexIterator';
- break;
-
- case 'recursiveregexiterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RecursiveRegexIterator';
- break;
-
- case 'directoryiterator':
- $compilationContext->headersManager->add('ext/spl/spl_directory');
- $classEntry = 'spl_ce_DirectoryIterator';
- break;
-
- case 'filesystemiterator':
- $compilationContext->headersManager->add('ext/spl/spl_directory');
- $classEntry = 'spl_ce_FilesystemIterator';
- break;
-
- case 'recursivedirectoryiterator':
- $compilationContext->headersManager->add('ext/spl/spl_directory');
- $classEntry = 'spl_ce_RecursiveDirectoryIterator';
- break;
-
- case 'globiterator':
- $compilationContext->headersManager->add('ext/spl/spl_directory');
- $classEntry = 'spl_ce_GlobIterator';
- break;
-
- case 'splfileobject':
- $compilationContext->headersManager->add('ext/spl/spl_directory');
- $classEntry = 'spl_ce_SplFileObject';
- break;
-
- case 'spltempfileobject':
- $compilationContext->headersManager->add('ext/spl/spl_directory');
- $classEntry = 'spl_ce_SplTempFileObject';
- break;
-
- case 'countable':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_Countable';
- break;
-
- case 'callbackfilteriterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_CallbackFilterIterator';
- break;
-
- case 'recursivecallbackfilteriterator':
- $compilationContext->headersManager->add('ext/spl/spl_iterators');
- $classEntry = 'spl_ce_RecursiveCallbackFilterIterator';
- break;
-
- case 'arrayobject':
- $compilationContext->headersManager->add('ext/spl/spl_array');
- $classEntry = 'spl_ce_ArrayObject';
- break;
-
- case 'splfixedarray':
- $compilationContext->headersManager->add('ext/spl/spl_fixedarray');
- $classEntry = 'spl_ce_SplFixedArray';
- break;
-
- case 'splpriorityqueue':
- $compilationContext->headersManager->add('ext/spl/spl_heap');
- $classEntry = 'spl_ce_SplPriorityQueue';
- break;
-
- case 'splfileinfo':
- $compilationContext->headersManager->add('ext/spl/spl_directory');
- $classEntry = 'spl_ce_SplFileInfo';
- break;
-
- case 'splheap':
- $compilationContext->headersManager->add('ext/spl/spl_heap');
- $classEntry = 'spl_ce_SplHeap';
- break;
-
- case 'splminheap':
- $compilationContext->headersManager->add('ext/spl/spl_heap');
- $classEntry = 'spl_ce_SplMinHeap';
- break;
-
- case 'splmaxheap':
- $compilationContext->headersManager->add('ext/spl/spl_heap');
- $classEntry = 'spl_ce_SplMaxHeap';
- break;
-
- case 'splstack':
- $compilationContext->headersManager->add('ext/spl/spl_dllist');
- $classEntry = 'spl_ce_SplStack';
- break;
-
- case 'splqueue':
- $compilationContext->headersManager->add('ext/spl/spl_dllist');
- $classEntry = 'spl_ce_SplQueue';
- break;
-
- case 'spldoublylinkedlist':
- $compilationContext->headersManager->add('ext/spl/spl_dllist');
- $classEntry = 'spl_ce_SplDoublyLinkedList';
- break;
-
- case 'stdclass':
- $classEntry = 'zend_standard_class_def';
- break;
-
- case 'closure':
- $compilationContext->headersManager->add('Zend/zend_closures');
- $classEntry = 'zend_ce_closure';
- break;
-
- case 'pdo':
- $compilationContext->headersManager->add('ext/pdo/php_pdo_driver');
- $classEntry = 'php_pdo_get_dbh_ce()';
- break;
-
- case 'pdostatement':
- $compilationContext->headersManager->add('kernel/main');
- $classEntry = $compilationContext->backend->fetchClassEntry('pdostatement');
- break;
-
- case 'pdoexception':
- $compilationContext->headersManager->add('ext/pdo/php_pdo_driver');
- $classEntry = 'php_pdo_get_exception()';
- break;
-
- /**
- * PHP Ext Date
- */
- case 'datetimeinterface':
- $compilationContext->headersManager->add('ext/date/php_date');
- $classEntry = 'php_date_get_interface_ce()';
- break;
-
- case 'datetime':
- $compilationContext->headersManager->add('ext/date/php_date');
- $classEntry = 'php_date_get_date_ce()';
- break;
-
- case 'datetimeimmutable':
- $compilationContext->headersManager->add('ext/date/php_date');
- $classEntry = 'php_date_get_immutable_ce()';
- break;
-
- case 'datetimezone':
- $compilationContext->headersManager->add('ext/date/php_date');
- $classEntry = 'php_date_get_timezone_ce()';
- break;
-
- case 'dateinterval':
- $compilationContext->headersManager->add('ext/date/php_date');
- $classEntry = 'php_date_get_interval_ce()';
- break;
-
- case 'dateperiod':
- $compilationContext->headersManager->add('ext/date/php_date');
- $classEntry = 'php_date_get_period_ce()';
- break;
-
- /**
- * PHP Ext session
- */
- case 'sessionhandlerinterface':
- $compilationContext->headersManager->add('ext/session/php_session');
- $classEntry = 'php_session_iface_entry';
- break;
-
- default:
- if (!$check) {
- throw new CompilerException('Unknown class entry for "'.$className.'"');
- } else {
- $classEntry = $compilationContext->backend->fetchClassEntry(escape_class(strtolower($className)));
- }
- }
-
- return $classEntry;
- }
-
/**
* Builds a class definition from reflection.
*
diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php
index 37daaadaa9..2973b13bdd 100644
--- a/Library/ClassMethod.php
+++ b/Library/ClassMethod.php
@@ -13,6 +13,7 @@
namespace Zephir;
+use Zephir\Classes\Entry as ClassEntry;
use Zephir\Detectors\WriteDetector;
use Zephir\Documentation\Docblock;
use Zephir\Documentation\DocblockParser;
@@ -175,26 +176,6 @@ class ClassMethod
*/
protected ?CallGathererPass $callGathererPass = null;
- /**
- * All classes must be in lower case.
- *
- * @var string[]
- */
- protected array $excludedClassEntries = [
- 'reflector',
- 'reflectionexception',
- 'reflection',
- 'reflectionfunctionabstract',
- 'reflectionfunction',
- 'reflectionparameter',
- 'reflectionclass',
- 'reflectionobject',
- 'reflectionmethod',
- 'reflectionproperty',
- 'reflectionextension',
- 'reflectionzendextension',
- ];
-
/**
* ClassMethod constructor.
*
@@ -769,7 +750,7 @@ public function getInternalParameters(): string
return '';
}
- return (string)$this->parameters->count().', ...';
+ return $this->parameters->count() .', ...';
}
/**
@@ -2334,8 +2315,12 @@ public function detectParam(array $parameter, CompilationContext $compilationCon
/**
* In case of unknown type, just return generic param type.
*/
- $param = sprintf('Z_PARAM_ZVAL(%s)', $name);
$hasDefaultNull = isset($parameter['default']['type']) && $parameter['default']['type'] === 'null';
+ if ($hasDefaultNull) {
+ $param = sprintf('Z_PARAM_ZVAL_OR_NULL(%s)', $name);
+ } else {
+ $param = sprintf('Z_PARAM_ZVAL(%s)', $name);
+ }
switch ($parameter['data-type']) {
case 'array':
@@ -2404,14 +2389,16 @@ public function detectParam(array $parameter, CompilationContext $compilationCon
break;
case 'variable':
- if (isset($parameter['cast']) && $parameter['cast']['type'] === 'variable' && $parameter['cast']['value']) {
- $classEntry = $this->detectClassNameEntry($parameter['cast']['value'], $compilationContext);
- if ($classEntry !== null) {
- if ($hasDefaultNull) {
- $param = sprintf('Z_PARAM_OBJECT_OF_CLASS_OR_NULL(%s, %s)', $name, $classEntry);
- } else {
- $param = sprintf('Z_PARAM_OBJECT_OF_CLASS(%s, %s)', $name, $classEntry);
- }
+ if (isset($parameter['cast']) &&
+ $parameter['cast']['type'] === 'variable' &&
+ $parameter['cast']['value'] &&
+ $this->classDefinition !== null
+ ) {
+ $classEntry = (new ClassEntry($parameter['cast']['value'], $compilationContext))->get();
+ if ($hasDefaultNull) {
+ $param = sprintf('Z_PARAM_OBJECT_OF_CLASS_OR_NULL(%s, %s)', $name, $classEntry);
+ } else {
+ $param = sprintf('Z_PARAM_OBJECT_OF_CLASS(%s, %s)', $name, $classEntry);
}
}
@@ -2421,149 +2408,6 @@ public function detectParam(array $parameter, CompilationContext $compilationCon
return $param;
}
- /**
- * @param string $className
- * @param CompilationContext $compilationContext
- * @return string|null
- * @throws Exception
- */
- private function detectClassNameEntry(string $className, CompilationContext $compilationContext): ?string
- {
- if ($this->classDefinition === null) {
- return null;
- }
-
- /**
- * Excluded classes.
- *
- * Cases when we can't retrieve class entry.
- * For example: php/ext/reflection, as there
- * are no PHP_INSTALL_HEADERS.
- */
- if (in_array(ltrim(strtolower($className), '\\'), $this->excludedClassEntries)) {
- return null;
- }
-
- $isAlias = false;
- $aliasManager = $this->classDefinition->getAliasManager();
- if (is_null($aliasManager)) {
- return null;
- }
- if ($aliasManager->isAlias($className)) {
- $isAlias = true;
- $className = $aliasManager->getAlias($className);
- }
-
- /**
- * PSR
- */
- if (strpos($className, 'Psr') === 0 || strpos($className, '\Psr') === 0) {
- $className = ltrim($className, '\\');
-
- $psrHeaderFiles = [
- 'psr_http_message' => [
- 'Psr\Http\Message\StreamInterface',
- 'Psr\Http\Message\StreamFactoryInterface',
- 'Psr\Http\Message\UriFactoryInterface',
- 'Psr\Http\Message\UriInterface',
- 'Psr\Http\Message\RequestInterface',
- 'Psr\Http\Message\RequestFactoryInterface',
- 'Psr\Http\Message\ResponseInterface',
- 'Psr\Http\Message\ResponseFactoryInterface',
- 'Psr\Http\Message\ServerRequestInterface',
- 'Psr\Http\Message\ServerRequestFactoryInterface',
- 'Psr\Http\Message\UploadedFileInterface',
- 'Psr\Http\Message\UploadedFileFactoryInterface',
- ],
- 'psr_simple_cache' => [
- 'Psr\SimpleCache\CacheInterface',
- 'Psr\SimpleCache\CacheException',
- 'Psr\SimpleCache\InvalidArgumentException',
- ],
- 'psr_container' => [
- 'Psr\Container\ContainerInterface',
- ],
- 'psr_log' => [
- 'Psr\Log\AbstractLogger',
- 'Psr\Log\LoggerInterface',
- 'Psr\Log\LogLevel',
- ],
- 'psr_link' => [
- 'Psr\Link\EvolvableLinkInterface',
- 'Psr\Link\EvolvableLinkProviderInterface',
- 'Psr\Link\LinkInterface',
- 'Psr\Link\LinkProviderInterface',
- ],
- 'psr_http_server_middleware' => [
- 'Psr\Http\Server\MiddlewareInterface',
- ],
- 'psr_http_server_handler' => [
- 'Psr\Http\Server\RequestHandlerInterface',
- ],
- ];
- foreach ($psrHeaderFiles as $file => $classes) {
- if (in_array($className, $classes)) {
- $compilationContext->headersManager->add('ext/psr/' . $file);
- }
- }
-
- return str_replace('\\', '', $className) . '_ce_ptr';
- }
-
- try {
- return $this
- ->classDefinition
- ->getClassEntryByClassName(
- preg_replace(['/^\\\\/'], '', $className),
- $compilationContext,
- false
- );
- } catch (CompilerException $exception) {
- // Continue below execution
- }
-
- $classNamespace = explode('\\', $className);
-
- /**
- * Full namespace with class name
- */
- if (strpos($className, '\\') === 0) {
- $classNamespace = array_values(array_filter($classNamespace));
-
- /**
- * External class
- */
- if (count($classNamespace) === 1) {
- return null;
- }
-
- /**
- * External class, we don't know its ClassEntry in C world.
- */
- if (!preg_match('/^'.$classNamespace[0].'/', $this->classDefinition->getNamespace())) {
- return null;
- }
-
- $className = end($classNamespace);
- array_pop($classNamespace);
- } else {
- /**
- * Check for partial namespace specification
- * Example: Oo\Param, while namespace at the top is Stub
- */
- $className = end($classNamespace);
- array_pop($classNamespace);
-
- if ($isAlias === false) {
- array_unshift($classNamespace, $this->classDefinition->getNamespace());
- }
- }
-
- $namespace = join('\\', $classNamespace);
-
- return (new ClassDefinition($namespace, $className))->getClassEntry();
- }
-
/**
* Get data type of method's parameter
*
diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php
new file mode 100644
index 0000000000..d477901ea5
--- /dev/null
+++ b/Library/Classes/Entry.php
@@ -0,0 +1,158 @@
+
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Zephir\Classes;
+
+use ReflectionClass;
+use ReflectionException;
+use Zephir\ClassDefinition;
+use Zephir\CompilationContext;
+use Zephir\Exception;
+
+/**
+ * Zend Class Entry detector
+ */
+class Entry
+{
+ public const NAMESPACE_SEPARATOR = '\\';
+
+ /**
+ * Class name
+ *
+ * As it was passed: partially or fully.
+ *
+ * @var string
+ */
+ private string $classname;
+
+ /**
+ * @var CompilationContext
+ */
+ private CompilationContext $compilationContext;
+
+ /**
+ * @var bool
+ */
+ private bool $isInternal = false;
+
+ /**
+ * Loaded via config/class-entries.php
+ *
+ * @var array
+ */
+ private array $classEntries;
+
+ /**
+ * Entry constructor.
+ *
+ * @param string $className
+ * @param CompilationContext $compilationContext
+ */
+ public function __construct(string $className, CompilationContext $compilationContext)
+ {
+ $this->compilationContext = $compilationContext;
+ $this->classname = $this->compilationContext->getFullName($className);
+
+ $this->classEntries = require __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config/class-entries.php';
+
+ foreach ($this->classEntries as $key => $val) {
+ unset($this->classEntries[$key]);
+ $this->classEntries[strtolower($key)] = $val;
+ }
+ }
+
+ /**
+ * @return string
+ * @throws Exception
+ * @throws ReflectionException
+ */
+ public function get(): string
+ {
+ $className = strtolower($this->classname);
+
+ /**
+ * Exclusions
+ */
+ if ($className === 'pdostatement') {
+ $this->compilationContext->headersManager->add('kernel/main');
+
+ return $this->compilationContext->backend->fetchClassEntry('pdostatement');
+ }
+
+ if (isset($this->classEntries[$className])) {
+ if (isset($this->classEntries[$className][1])) {
+ $this->compilationContext->headersManager->add($this->classEntries[$className][1]);
+ }
+
+ return $this->classEntries[$className][0];
+ }
+
+ if (class_exists($this->classname)) {
+ $reflection = new ReflectionClass($this->classname);
+ $className = $reflection->getName();
+
+ /**
+ * Check if class is defined internally by an extension, or the core.
+ */
+ if ($reflection->isInternal()) {
+ return sprintf(
+ 'zephir_get_internal_ce(SL("%s"))',
+ strtolower($reflection->getName()),
+ );
+ }
+
+ $classNamespace = explode(self::NAMESPACE_SEPARATOR, $reflection->getNamespaceName());
+ } else {
+ $className = $this->classname;
+ $classNamespace = explode(self::NAMESPACE_SEPARATOR, $className);
+ }
+
+ /**
+ * External class, we don't know its ClassEntry in C world.
+ */
+ if (!$this->isInternalClass($classNamespace[0])) {
+ $className = str_replace(self::NAMESPACE_SEPARATOR, self::NAMESPACE_SEPARATOR.self::NAMESPACE_SEPARATOR, strtolower($className));
+
+ return sprintf(
+ //'zend_lookup_class_ex(zend_string_init(ZEND_STRL("%s"), 0), NULL, 0)',
+ 'zephir_get_internal_ce(SL("%s"))',
+ $className,
+ );
+ }
+
+ $className = end($classNamespace);
+ array_pop($classNamespace);
+ $namespace = join(self::NAMESPACE_SEPARATOR, $classNamespace);
+
+ return (new ClassDefinition($namespace, $className))->getClassEntry();
+ }
+
+ public function isInternal(): bool
+ {
+ return $this->isInternal;
+ }
+
+ /**
+ * Detect if start of namespace class
+ * belongs to project namespace.
+ *
+ * @param string $className
+ * @return bool
+ */
+ private function isInternalClass(string $className): bool
+ {
+ $this->isInternal = preg_match('/^'.$className.'/', $this->compilationContext->classDefinition->getNamespace()) === 1;
+
+ return $this->isInternal;
+ }
+}
diff --git a/Library/CodePrinter.php b/Library/CodePrinter.php
index 34ab1fad44..35bb839a47 100644
--- a/Library/CodePrinter.php
+++ b/Library/CodePrinter.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir;
/**
@@ -18,20 +20,20 @@
*/
class CodePrinter
{
- protected $code;
+ protected string $code = '';
- protected $lastLine;
+ protected string $lastLine = '';
- protected $level = 0;
+ protected int $level = 0;
- protected $currentPrints = 0;
+ protected int $currentPrints = 0;
/**
* Adds a line to the output without the automatic line feed.
*
* @param string $code
*/
- public function outputNoLineFeed($code)
+ public function outputNoLineFeed(string $code): void
{
$this->lastLine = $code;
$this->code .= str_repeat("\t", $this->level).$code;
@@ -42,7 +44,7 @@ public function outputNoLineFeed($code)
*
* @param string $code
*/
- public function preOutput($code)
+ public function preOutput(string $code): void
{
$this->lastLine = $code;
$this->code = str_repeat("\t", $this->level).$code.PHP_EOL.$this->code;
@@ -54,7 +56,7 @@ public function preOutput($code)
*
* @param string $code
*/
- public function preOutputNoLineFeed($code)
+ public function preOutputNoLineFeed(string $code): void
{
$this->lastLine = $code;
$this->code = str_repeat("\t", $this->level).$code.$this->code;
@@ -65,7 +67,7 @@ public function preOutputNoLineFeed($code)
*
* @param string $code
*/
- public function preOutputNoLevel($code)
+ public function preOutputNoLevel(string $code): void
{
$this->lastLine = $code;
$this->code = $code.PHP_EOL.$this->code;
@@ -77,7 +79,7 @@ public function preOutputNoLevel($code)
*
* @param string $code
*/
- public function outputNoIndent($code)
+ public function outputNoIndent(string $code): void
{
$this->lastLine = $code;
$this->code .= $code.PHP_EOL;
@@ -88,6 +90,7 @@ public function outputNoIndent($code)
* Add code to the output.
*
* @param string $code
+ * @param bool $appendEOL
*/
public function output(string $code, bool $appendEOL = true): void
{
@@ -102,7 +105,7 @@ public function output(string $code, bool $appendEOL = true): void
* @param $docblock
* @param bool $replaceTab
*/
- public function outputDocBlock($docblock, $replaceTab = true)
+ public function outputDocBlock($docblock, bool $replaceTab = true): void
{
$code = '';
$docblock = '/'.$docblock.'/';
@@ -125,7 +128,7 @@ public function outputDocBlock($docblock, $replaceTab = true)
*
* @param string $code
*/
- public function outputNoLevel($code)
+ public function outputNoLevel(string $code): void
{
$this->lastLine = $code;
$this->code .= $code.PHP_EOL;
@@ -139,7 +142,7 @@ public function outputNoLevel($code)
*
* @param bool $ifPrevNotBlank
*/
- public function preOutputBlankLine($ifPrevNotBlank = false)
+ public function preOutputBlankLine(bool $ifPrevNotBlank = false): void
{
if (!$ifPrevNotBlank) {
$this->code = PHP_EOL.$this->code;
@@ -161,7 +164,7 @@ public function preOutputBlankLine($ifPrevNotBlank = false)
*
* @param bool $ifPrevNotBlank
*/
- public function outputBlankLine($ifPrevNotBlank = false)
+ public function outputBlankLine(bool $ifPrevNotBlank = false): void
{
if (!$ifPrevNotBlank) {
$this->code .= PHP_EOL;
@@ -179,7 +182,7 @@ public function outputBlankLine($ifPrevNotBlank = false)
/**
* Increase the indentation level.
*/
- public function increaseLevel()
+ public function increaseLevel(): void
{
++$this->level;
}
@@ -187,12 +190,12 @@ public function increaseLevel()
/**
* Decrease the indentation level.
*/
- public function decreaseLevel()
+ public function decreaseLevel(): void
{
--$this->level;
}
- public function setLevel($level)
+ public function setLevel(int $level): void
{
$this->level = $level;
}
@@ -204,7 +207,7 @@ public function setLevel($level)
*/
public function getOutput(): string
{
- return (string) $this->code;
+ return $this->code;
}
/**
@@ -212,7 +215,7 @@ public function getOutput(): string
*
* @return int
*/
- public function getNumberPrints()
+ public function getNumberPrints(): int
{
return $this->currentPrints;
}
@@ -220,14 +223,14 @@ public function getNumberPrints()
/**
* Frees memory used within the code.
*/
- public function clear()
+ public function clear(): void
{
- $this->code = null;
- $this->lastLine = null;
+ $this->code = '';
+ $this->lastLine = '';
$this->level = 0;
}
- public function duplicate()
+ public function duplicate(): CodePrinter
{
$printer = new self();
$printer->setLevel($this->level);
diff --git a/Library/CompilationContext.php b/Library/CompilationContext.php
index d0c254b743..d58e69a1b3 100644
--- a/Library/CompilationContext.php
+++ b/Library/CompilationContext.php
@@ -9,10 +9,14 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir;
use Psr\Log\LoggerInterface;
+use Zephir\Cache\FunctionCache;
use Zephir\Exception\CompilerException;
+use Zephir\Passes\StaticTypeInference;
/**
* CompilationContext.
@@ -22,182 +26,180 @@
class CompilationContext
{
/**
- * @var EventsManager
+ * @var EventsManager|null
*/
- public $eventsManager;
+ public ?EventsManager $eventsManager = null;
/**
* Compiler.
*
- * @var Compiler
+ * @var Compiler|null
*/
- public $compiler;
+ public ?Compiler $compiler = null;
/**
* Current code printer.
*
- * @var CodePrinter
+ * @var CodePrinter|null
*/
- public $codePrinter;
+ public ?CodePrinter $codePrinter = null;
/**
* Whether the current method is static or not.
*
* @var bool
*/
- public $staticContext;
+ public bool $staticContext = false;
/**
* Code printer for the header.
*
- * @var CodePrinter
+ * @var CodePrinter|null
*/
- public $headerPrinter;
+ public ?CodePrinter $headerPrinter = null;
/**
* Current symbol table.
*
- * @var SymbolTable
+ * @var SymbolTable|null
*/
- public $symbolTable;
+ public ?SymbolTable $symbolTable = null;
/**
* Type inference data.
*
- * @var \Zephir\Passes\StaticTypeInference
+ * @var StaticTypeInference|null
*/
- public $typeInference;
+ public ?StaticTypeInference $typeInference = null;
/**
* Represents the class currently being compiled.
*
- * @var ClassDefinition
+ * @var ClassDefinition|null
*/
- public $classDefinition;
+ public ?ClassDefinition $classDefinition = null;
/**
* Current method or function that being compiled.
*
- * @var ClassMethod|FunctionDefinition
+ * @var ClassMethod|FunctionDefinition|null
*/
- public $currentMethod;
+ public ?ClassMethod $currentMethod = null;
/**
* Methods warm-up.
*
- * @var MethodCallWarmUp
+ * @var MethodCallWarmUp|null
*/
- public $methodWarmUp;
+ public ?MethodCallWarmUp $methodWarmUp = null;
/**
* Represents the c-headers added to the file.
*
- * @var HeadersManager
+ * @var HeadersManager|null
*/
- public $headersManager;
+ public ?HeadersManager $headersManager = null;
/**
* Represents interned strings and concatenations made in the project.
*
- * @var StringsManager
+ * @var StringsManager|null
*/
- public $stringsManager;
+ public ?StringsManager $stringsManager = null;
/**
* Tells if the the compilation is being made inside a cycle/loop.
*
* @var int
*/
- public $insideCycle = 0;
+ public int $insideCycle = 0;
/**
* Tells if the the compilation is being made inside a try/catch block.
*
* @var int
*/
- public $insideTryCatch = 0;
+ public int $insideTryCatch = 0;
/**
* Tells if the the compilation is being made inside a switch.
*
* @var int
*/
- public $insideSwitch = 0;
+ public int $insideSwitch = 0;
/**
* Current cycle/loop block.
*
* @var array
*/
- public $cycleBlocks = [];
+ public array $cycleBlocks = [];
/**
* The current branch, variables declared in conditional branches
* must be market if they're used out of those branches.
*/
- public $currentBranch = 0;
+ public int $currentBranch = 0;
/**
* Global consecutive for try/catch blocks.
*
* @var int
*/
- public $currentTryCatch = 0;
+ public int $currentTryCatch = 0;
/**
* Helps to create graphs of conditional/jump branches in a specific method.
*
- * @var BranchManager
+ * @var BranchManager|null
*/
- public $branchManager;
+ public ?BranchManager $branchManager = null;
/**
* Manages both function and method call caches.
*
- * @var CacheManager
+ * @var CacheManager|null
*/
- public $cacheManager;
+ public ?CacheManager $cacheManager = null;
/**
* Manages class renamings using keyword 'use'.
*
- * @var AliasManager
+ * @var AliasManager|null
*/
- public $aliasManager;
+ public ?AliasManager $aliasManager = null;
/**
* Function Cache.
*
- * @var Cache\FunctionCache
+ * @var FunctionCache|null
*/
- public $functionCache;
+ public ?FunctionCache $functionCache = null;
/**
* Global config.
*
- * @var Config
+ * @var Config|null
*/
- public $config;
+ public ?Config $config = null;
/**
* Global logger.
*
- * @var LoggerInterface
+ * @var LoggerInterface|null
*/
- public $logger;
+ public ?LoggerInterface $logger = null;
/**
* The current backend.
*
- * @var BaseBackend
+ * @var BaseBackend|null
*/
- public $backend;
+ public ?BaseBackend $backend = null;
/**
* Transform class/interface name to FQN format.
*
- * TODO: WHY WHY :'(
- *
* @param string $className
*
* @return string
diff --git a/Library/CompiledExpression.php b/Library/CompiledExpression.php
index 62c5e947cc..913623010e 100644
--- a/Library/CompiledExpression.php
+++ b/Library/CompiledExpression.php
@@ -9,8 +9,12 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir;
+use Closure;
+
/**
* CompiledExpression.
*
@@ -19,18 +23,18 @@
*/
class CompiledExpression implements TypeAwareInterface
{
- protected $type;
+ protected string $type;
- protected $code;
+ protected ?string $code;
- protected $originalExpr;
+ protected ?array $originalExpr;
/**
* @param string $type
- * @param string $code
- * @param array $originalExpr
+ * @param string|null $code
+ * @param array|null $originalExpr
*/
- public function __construct($type, $code, $originalExpr)
+ public function __construct(string $type, ?string $code, ?array $originalExpr = null)
{
$this->type = $type;
$this->code = $code;
@@ -42,7 +46,7 @@ public function __construct($type, $code, $originalExpr)
*
* @return string
*/
- public function getType()
+ public function getType(): string
{
return $this->type;
}
@@ -50,9 +54,9 @@ public function getType()
/**
* Returns the code produced by the compiled expression.
*
- * @return string
+ * @return string|null
*/
- public function getCode()
+ public function getCode(): ?string
{
return $this->code;
}
@@ -60,9 +64,9 @@ public function getCode()
/**
* Original AST code that produced the code.
*
- * @return array
+ * @return array|null
*/
- public function getOriginal()
+ public function getOriginal(): ?array
{
return $this->originalExpr;
}
@@ -72,7 +76,7 @@ public function getOriginal()
*
* @return string
*/
- public function getBooleanCode()
+ public function getBooleanCode(): string
{
if ($this->code && ('true' == $this->code || true === $this->code)) {
return '1';
@@ -90,7 +94,7 @@ public function getBooleanCode()
*
* @return bool
*/
- public function isIntCompatibleType()
+ public function isIntCompatibleType(): bool
{
switch ($this->type) {
case 'int':
@@ -110,7 +114,7 @@ public function isIntCompatibleType()
*
* @return bool
*/
- public function isCharCompatibleType()
+ public function isCharCompatibleType(): bool
{
switch ($this->type) {
case 'char':
@@ -127,14 +131,14 @@ public function isCharCompatibleType()
* because it's missing some bound parts, this method resolves the missing parts
* returning the generated code.
*
- * @param string $result
+ * @param string|null $result
* @param CompilationContext $compilationContext
*
* @return string
*/
- public function resolve($result, CompilationContext $compilationContext)
+ public function resolve(?string $result, CompilationContext $compilationContext): string
{
- if ($this->code instanceof \Closure) {
+ if ($this->code instanceof Closure) {
$code = $this->code;
if (!$result) {
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
diff --git a/Library/Compiler.php b/Library/Compiler.php
index 4e4e8d0515..498aca6ceb 100644
--- a/Library/Compiler.php
+++ b/Library/Compiler.php
@@ -13,6 +13,7 @@
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
+use ReflectionException;
use Zephir\Code\Builder\Struct;
use Zephir\Compiler\CompilerFileFactory;
use Zephir\Exception\CompilerException;
@@ -33,17 +34,25 @@ final class Compiler
{
use LoggerAwareTrait;
- /** @var BaseBackend */
- public $backend;
+ /**
+ * @var BaseBackend
+ */
+ public BaseBackend $backend;
- /** @var FunctionDefinition[] */
- public $functionDefinitions = [];
+ /**
+ * @var FunctionDefinition[]
+ */
+ public array $functionDefinitions = [];
- /** @var CompilerFile[] */
- private $files = [];
+ /**
+ * @var CompilerFile[]
+ */
+ private array $files = [];
- /** @var string[] */
- private $anonymousFiles = [];
+ /**
+ * @var string[]
+ */
+ private array $anonymousFiles = [];
/**
* Additional initializer code.
@@ -51,53 +60,83 @@ final class Compiler
*
* @var array
*/
- private $internalInitializers = [];
+ private array $internalInitializers = [];
- /** @var ClassDefinition[] */
- private $definitions = [];
+ /**
+ * @var ClassDefinition[]
+ */
+ private array $definitions = [];
- /** @var string[] */
- private $compiledFiles = [];
+ /**
+ * @var string[]
+ */
+ private array $compiledFiles = [];
- private $constants = [];
+ private array $constants = [];
- private $globals = [];
+ private array $globals = [];
- private $externalDependencies = [];
+ private array $externalDependencies = [];
- /** @var ClassDefinition[] */
- private static $internalDefinitions = [];
+ /**
+ * @var ClassDefinition[]
+ */
+ private static array $internalDefinitions = [];
- private static $loadedPrototypes = false;
+ /**
+ * @var bool
+ */
+ private static bool $loadedPrototypes = false;
- private $extraFiles = [];
+ /**
+ * @var array
+ */
+ private array $extraFiles = [];
- /** @var Config */
- private $config;
+ /**
+ * @var Config
+ */
+ private Config $config;
- /** @var Parser\Manager */
- private $parserManager;
+ /**
+ * @var Parser\Manager
+ */
+ private Parser\Manager $parserManager;
- /** @var StringsManager */
- private $stringManager;
+ /**
+ * @var StringsManager
+ */
+ private StringsManager $stringManager;
- /** @var FcallManagerInterface */
- private $fcallManager;
+ /**
+ * @var FcallManagerInterface
+ */
+ private FcallManagerInterface $fcallManager;
- /** @var string|null */
- private $prototypesPath;
+ /**
+ * @var string|null
+ */
+ private ?string $prototypesPath;
- /** @var string|null */
- private $optimizersPath;
+ /**
+ * @var string|null
+ */
+ private ?string $optimizersPath;
- /** @var string|null */
- private $templatesPath;
+ /**
+ * @var string|null
+ */
+ private ?string $templatesPath;
- /** @var FileSystemInterface */
- private $filesystem;
+ /**
+ * @var FileSystemInterface
+ */
+ private FileSystemInterface $filesystem;
- /** @var CompilerFileFactory */
- private $compilerFileFactory;
+ /**
+ * @var CompilerFileFactory
+ */
+ private CompilerFileFactory $compilerFileFactory;
/**
* Compiler constructor.
@@ -138,7 +177,7 @@ public function __construct(
/**
* @param string $prototypesPath
*/
- public function setPrototypesPath($prototypesPath)
+ public function setPrototypesPath(string $prototypesPath): void
{
$this->prototypesPath = $prototypesPath;
}
@@ -150,7 +189,7 @@ public function setPrototypesPath($prototypesPath)
*
* @throws IllegalStateException in case of absence internal prototypes directory
*/
- private function resolvePrototypesPath()
+ private function resolvePrototypesPath(): ?string
{
$prototypesPath = $this->prototypesPath;
@@ -169,7 +208,7 @@ private function resolvePrototypesPath()
/**
* @param string $optimizersPath
*/
- public function setOptimizersPath($optimizersPath)
+ public function setOptimizersPath(string $optimizersPath): void
{
$this->optimizersPath = $optimizersPath;
}
@@ -181,7 +220,7 @@ public function setOptimizersPath($optimizersPath)
*
* @throws IllegalStateException in case of absence internal optimizers directory
*/
- private function resolveOptimizersPath()
+ private function resolveOptimizersPath(): ?string
{
$optimizersPath = $this->optimizersPath;
@@ -212,7 +251,7 @@ public function setTemplatesPath(string $templatesPath): void
*
* @return Parser\Manager
*/
- public function getParserManager()
+ public function getParserManager(): Parser\Manager
{
return $this->parserManager;
}
@@ -251,7 +290,7 @@ public function addFunction(FunctionDefinition $func, $statement = null)
* @throws IllegalStateException
* @throws ParseException
*/
- public function loadExternalClass($className, $location)
+ public function loadExternalClass(string $className, string $location): bool
{
$filePath = $location.\DIRECTORY_SEPARATOR.
strtolower(str_replace('\\', \DIRECTORY_SEPARATOR, $className)).'.zep';
@@ -287,7 +326,7 @@ public function loadExternalClass($className, $location)
*
* @return bool
*/
- public function isClass($className)
+ public function isClass(string $className): bool
{
foreach ($this->definitions as $key => $value) {
if (!strcasecmp($key, $className) && 'class' === $value->getType()) {
@@ -295,14 +334,12 @@ public function isClass($className)
}
}
- /*
+ /**
* Try to autoload the class from an external dependency
*/
- if (count($this->externalDependencies)) {
- foreach ($this->externalDependencies as $namespace => $location) {
- if (preg_match('#^'.$namespace.'\\\\#i', $className)) {
- return $this->loadExternalClass($className, $location);
- }
+ foreach ($this->externalDependencies as $namespace => $location) {
+ if (preg_match('#^'.$namespace.'\\\\#i', $className)) {
+ return $this->loadExternalClass($className, $location);
}
}
@@ -320,7 +357,7 @@ public function isClass($className)
* @throws IllegalStateException
* @throws ParseException
*/
- public function isInterface($className)
+ public function isInterface(string $className): bool
{
foreach ($this->definitions as $key => $value) {
if (!strcasecmp($key, $className) && 'interface' === $value->getType()) {
@@ -328,14 +365,12 @@ public function isInterface($className)
}
}
- /*
+ /**
* Try to autoload the class from an external dependency
*/
- if (count($this->externalDependencies)) {
- foreach ($this->externalDependencies as $namespace => $location) {
- if (preg_match('#^'.$namespace.'\\\\#i', $className)) {
- return $this->loadExternalClass($className, $location);
- }
+ foreach ($this->externalDependencies as $namespace => $location) {
+ if (preg_match('#^'.$namespace.'\\\\#i', $className)) {
+ return $this->loadExternalClass($className, $location);
}
}
@@ -349,7 +384,7 @@ public function isInterface($className)
*
* @return bool
*/
- public function isBundledClass($className)
+ public function isBundledClass(string $className): bool
{
return class_exists($className, false);
}
@@ -361,7 +396,7 @@ public function isBundledClass($className)
*
* @return bool
*/
- public function isBundledInterface($className)
+ public function isBundledInterface(string $className): bool
{
return interface_exists($className, false);
}
@@ -373,7 +408,7 @@ public function isBundledInterface($className)
*
* @return ClassDefinition|false returns false if no class definition is found
*/
- public function getClassDefinition($className)
+ public function getClassDefinition(string $className)
{
foreach ($this->definitions as $key => $value) {
if (!strcasecmp($key, $className)) {
@@ -403,9 +438,9 @@ public function addClassDefinition(CompilerFileAnonymous $file, ClassDefinition
*
* @return ClassDefinition
*
- * @throws \ReflectionException
+ * @throws ReflectionException
*/
- public function getInternalClassDefinition($className)
+ public function getInternalClassDefinition(string $className): ClassDefinition
{
if (!isset(self::$internalDefinitions[$className])) {
$reflection = new \ReflectionClass($className);
@@ -422,7 +457,7 @@ public function getInternalClassDefinition($className)
*
* @return bool
*/
- public function isConstant($name)
+ public function isConstant(string $name): bool
{
return isset($this->constants[$name]);
}
@@ -431,8 +466,9 @@ public function isConstant($name)
* Returns a Zephir Constant by its name.
*
* @param string $name
+ * @return mixed
*/
- public function getConstant($name)
+ public function getConstant(string $name)
{
return $this->constants[$name];
}
@@ -456,7 +492,7 @@ public function setExtensionGlobals(array $globals)
*
* @return bool
*/
- public function isExtensionGlobal($name)
+ public function isExtensionGlobal(string $name): bool
{
return isset($this->globals[$name]);
}
@@ -468,7 +504,7 @@ public function isExtensionGlobal($name)
*
* @return array
*/
- public function getExtensionGlobal($name)
+ public function getExtensionGlobal(string $name): array
{
return $this->globals[$name];
}
@@ -480,7 +516,7 @@ public function getExtensionGlobal($name)
*
* @return string
*/
- public function getGccFlags($development = false)
+ public function getGccFlags(bool $development = false): string
{
if (is_windows()) {
// TODO
@@ -510,7 +546,7 @@ public function getGccFlags($development = false)
*
* @return string
*/
- public function getPhpIncludeDirs()
+ public function getPhpIncludeDirs(): string
{
$this->filesystem->system('php-config --includes', 'stdout', 'php-includes');
@@ -1836,12 +1872,12 @@ public function createProjectFiles($project)
return $needConfigure;
}
- public function generateFunctionInformation()
+ public function generateFunctionInformation(): array
{
$headerPrinter = new CodePrinter();
$entryPrinter = new CodePrinter();
- /*
+ /**
* Specifying Argument Information
*/
foreach ($this->functionDefinitions as $func) {
@@ -1974,8 +2010,8 @@ public function generatePackageDependenciesM4($contentM4)
$pkgconfigM4 .= $pkgM4Buf;
$extraCFlags .= '$PHP_'.strtoupper($pkg).'_INCS ';
}
- $contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4);
+ $contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4);
$contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', $pkgconfigM4, $contentM4);
return $contentM4;
@@ -1993,7 +2029,7 @@ public function generatePackageDependenciesM4($contentM4)
*
* @throws IllegalStateException
*/
- private function preCompile($filePath)
+ private function preCompile(string $filePath)
{
if (!$this->parserManager->isAvailable()) {
throw new IllegalStateException($this->parserManager->requirements());
@@ -2021,7 +2057,7 @@ private function preCompile($filePath)
* @throws IllegalStateException
* @throws InvalidArgumentException
*/
- private function recursivePreCompile($path)
+ private function recursivePreCompile(string $path)
{
if (!is_dir($path)) {
throw new InvalidArgumentException(
@@ -2034,7 +2070,7 @@ private function recursivePreCompile($path)
);
}
- /*
+ /**
* Pre compile all files.
*/
$iterator = new \RecursiveIteratorIterator(
@@ -2133,7 +2169,7 @@ private function recursiveDeletePath($path, $mask)
*
* @throws Exception
*/
- private function loadConstantsSources($constantsSources)
+ private function loadConstantsSources(array $constantsSources)
{
foreach ($constantsSources as $constantsSource) {
if (!file_exists($constantsSource)) {
@@ -2155,12 +2191,12 @@ private function loadConstantsSources($constantsSources)
/**
* Process config.w32 sections.
*
- * @param array $sources
+ * @param array $sources
* @param string $project
*
* @return array
*/
- private function processAddSources($sources, $project)
+ private function processAddSources(array $sources, string $project): array
{
$groupSources = [];
foreach ($sources as $source) {
@@ -2168,8 +2204,10 @@ private function processAddSources($sources, $project)
if (!isset($groupSources[$dirName])) {
$groupSources[$dirName] = [];
}
+
$groupSources[$dirName][] = basename($source);
}
+
$groups = [];
foreach ($groupSources as $dirname => $files) {
$groups[] = 'ADD_SOURCES(configure_module_dirname + "/'.$dirname.'", "'.
@@ -2221,7 +2259,7 @@ private function assertRequiredExtensionsIsPresent()
*
* @return bool
*/
- private function checkKernelFile($src, $dst)
+ private function checkKernelFile(string $src, string $dst): bool
{
if (preg_match('#kernels/ZendEngine[2-9]/concat\.#', $src)) {
return true;
@@ -2231,7 +2269,7 @@ private function checkKernelFile($src, $dst)
return false;
}
- return md5_file($src) == md5_file($dst);
+ return md5_file($src) === md5_file($dst);
}
/**
@@ -2241,7 +2279,7 @@ private function checkKernelFile($src, $dst)
*
* @return bool
*/
- private function checkKernelFiles()
+ private function checkKernelFiles(): bool
{
$kernelPath = 'ext'.\DIRECTORY_SEPARATOR.'kernel';
@@ -2281,7 +2319,7 @@ private function checkKernelFiles()
*
* @return string
*/
- private function checkDirectory()
+ private function checkDirectory(): string
{
$namespace = $this->config->get('namespace');
if (!$namespace) {
@@ -2316,7 +2354,7 @@ private function checkDirectory()
*
* @return string
*/
- private function getGccVersion()
+ private function getGccVersion(): string
{
if (is_windows()) {
return '0.0.0';
diff --git a/Library/CompilerFile.php b/Library/CompilerFile.php
index 7c83ea8a54..29fb76d5eb 100644
--- a/Library/CompilerFile.php
+++ b/Library/CompilerFile.php
@@ -639,7 +639,7 @@ public function preCompile(Compiler $compiler)
if (!$class && !$interface) {
throw new CompilerException(
'Every file must contain at least a class or an interface',
- isset($topStatement) ? $topStatement : null
+ $topStatement ?? null
);
}
@@ -1154,7 +1154,7 @@ protected function processShortcuts(array $property, ClassDefinition $classDefin
*
* @return string
*/
- protected function getFullName($name)
+ protected function getFullName(string $name): string
{
return fqcn($name, $this->namespace, $this->aliasManager);
}
@@ -1163,11 +1163,11 @@ protected function getFullName($name)
* Create returns type list.
*
* @param array $types
- * @param bool $annotated
+ * @param bool $annotated
*
* @return array
*/
- protected function createReturnsType(array $types, $annotated = false)
+ protected function createReturnsType(array $types, bool $annotated = false): ?array
{
if (!$types) {
return null;
@@ -1178,7 +1178,7 @@ protected function createReturnsType(array $types, $annotated = false)
foreach ($types as $type) {
$list[] = [
'type' => $annotated ? 'return-type-annotation' : 'return-type-paramater',
- 'data-type' => 'mixed' == $type ? 'variable' : $type,
+ 'data-type' => 'mixed' === $type ? 'variable' : $type,
'mandatory' => false,
];
}
diff --git a/Library/Logger/Formatter/CompilerFormatter.php b/Library/Logger/Formatter/CompilerFormatter.php
index 4d61d7a48c..34fc1406e4 100644
--- a/Library/Logger/Formatter/CompilerFormatter.php
+++ b/Library/Logger/Formatter/CompilerFormatter.php
@@ -9,29 +9,35 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Logger\Formatter;
use Monolog\Formatter\LineFormatter;
use Zephir\Config;
+use function array_key_exists;
+use function count;
+use function is_array;
+
/**
* Formatter for warnings/notices/errors generated in compilation.
*/
final class CompilerFormatter extends LineFormatter
{
- const SIMPLE_FORMAT = " %level_name%: %message% in %file% on line %line% %type%\n";
+ public const SIMPLE_FORMAT = " %level_name%: %message% in %file% on line %line% %type%\n";
/**
* @var Config
*/
- private $config;
+ private Config $config;
/**
* The contents of the files that are involved in the log message.
*
* @var array
*/
- private $filesContent = [];
+ private array $filesContent = [];
public function __construct(Config $config)
{
@@ -41,7 +47,8 @@ public function __construct(Config $config)
}
/**
- * {@inheritdoc}
+ * @param array $record
+ * @return string
*/
public function format(array $record): string
{
@@ -60,8 +67,8 @@ public function format(array $record): string
// ignore empty context or invalid format
if (!empty($vars['context']) &&
- \is_array($vars['context']) &&
- 2 == \count($vars['context'])
+ is_array($vars['context']) &&
+ 2 == count($vars['context'])
) {
$type = $vars['context'][0];
$node = $vars['context'][1];
@@ -70,7 +77,7 @@ public function format(array $record): string
return '';
}
- $vars['type'] = "[{$type}]";
+ $vars['type'] = "[$type]";
if (!isset($node['file'])) {
$vars['file'] = 'unknown';
@@ -96,15 +103,14 @@ public function format(array $record): string
}
$output = $this->replacePlaceholders($vars, $output);
- $output = $this->cleanExtraPlaceholders($output);
- return $output;
+ return $this->cleanExtraPlaceholders($output);
}
private function replacePlaceholders(array $vars, $output)
{
// WARNING -> Warning
- if (\array_key_exists('level_name', $vars)) {
+ if (array_key_exists('level_name', $vars)) {
$vars['level_name'] = ucfirst(strtolower($vars['level_name']));
}
@@ -139,7 +145,7 @@ private function replacePlaceholders(array $vars, $output)
*
* @return string
*/
- private function cleanExtraPlaceholders($output)
+ private function cleanExtraPlaceholders(string $output): string
{
if (false !== strpos($output, '%')) {
$output = preg_replace('/%(?:extra|context)\..+?%/', '', $output);
@@ -158,7 +164,7 @@ private function cleanExtraPlaceholders($output)
*
* @return array
*/
- private function getFileContents($file)
+ private function getFileContents(string $file): array
{
if (!isset($this->filesContent[$file])) {
$this->filesContent[$file] = file_exists($file) ? file($file) : [];
diff --git a/Library/Operators/BaseOperator.php b/Library/Operators/BaseOperator.php
index 147d3283c5..bd8e96b608 100644
--- a/Library/Operators/BaseOperator.php
+++ b/Library/Operators/BaseOperator.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators;
use Zephir\CompilationContext;
@@ -36,7 +38,7 @@ class BaseOperator
* @param bool $expecting
* @param Variable|null $expectingVariable
*/
- public function setExpectReturn(bool $expecting, Variable $expectingVariable = null)
+ public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null)
{
$this->expecting = $expecting;
$this->expectingVariable = $expectingVariable;
@@ -47,12 +49,12 @@ public function setExpectReturn(bool $expecting, Variable $expectingVariable = n
* store the result. This method returns a variable that is always stored in the heap.
*
* @param CompilationContext $compilationContext
- * @param array $expression
- * @param bool $init
+ * @param array $expression
+ * @param bool $init
*
* @return Variable
*/
- public function getExpectedNonLiteral(CompilationContext $compilationContext, $expression, $init = true)
+ public function getExpectedNonLiteral(CompilationContext $compilationContext, array $expression, bool $init = true): ?Variable
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
@@ -80,19 +82,19 @@ public function getExpectedNonLiteral(CompilationContext $compilationContext, $e
* store the result.
*
* @param CompilationContext $compilationContext
- * @param array $expression
- * @param bool $init
+ * @param array $expression
+ * @param bool $init
*
* @return Variable
*/
- public function getExpected(CompilationContext $compilationContext, $expression, $init = true)
+ public function getExpected(CompilationContext $compilationContext, array $expression, bool $init = true): ?Variable
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
- if ('variable' == $symbolVariable->getType()) {
+ if ('variable' === $symbolVariable->getType()) {
if (!$init) {
return $symbolVariable;
}
@@ -130,19 +132,18 @@ public function getExpected(CompilationContext $compilationContext, $expression,
* on every iteration.
*
* @param CompilationContext $compilationContext
- * @param array $expression
- * @param string $type
+ * @param string $type
*
* @return Variable
*/
- public function getExpectedComplexLiteral(CompilationContext $compilationContext, $expression, $type = 'variable')
+ public function getExpectedComplexLiteral(CompilationContext $compilationContext, string $type = 'variable'): ?Variable
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
- if ($symbolVariable->getType() == $type || 'return_value' == $symbolVariable->getName()) {
+ if ($symbolVariable->getType() === $type || 'return_value' === $symbolVariable->getName()) {
$symbolVariable->initVariant($compilationContext);
} else {
if (!$this->readOnly) {
diff --git a/Library/Operators/Logical/AndOperator.php b/Library/Operators/Logical/AndOperator.php
index 4cd4cf1efb..dbdf30da1f 100644
--- a/Library/Operators/Logical/AndOperator.php
+++ b/Library/Operators/Logical/AndOperator.php
@@ -9,8 +9,11 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Logical;
+use Exception;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
use Zephir\Exception\CompilerException;
@@ -23,14 +26,20 @@ class AndOperator extends LogicalBaseOperator
protected string $bitOperator = '&&';
- public function compile($expression, CompilationContext $compilationContext)
+ /**
+ * @param $expression
+ * @param CompilationContext $compilationContext
+ * @return CompiledExpression
+ * @throws \Zephir\Exception
+ */
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
- throw new \Exception('Missing left part of the expression');
+ throw new Exception('Missing left part of the expression');
}
if (!isset($expression['right'])) {
- throw new \Exception('Missing right part of the expression');
+ throw new Exception('Missing right part of the expression');
}
$leftExpr = new Expression($expression['left']);
@@ -92,7 +101,6 @@ public function compile($expression, CompilationContext $compilationContext)
$statement->compile($compilationContext);
$compilationContext->codePrinter->output('if ('.$flagVariable->getName().') {');
-
$compilationContext->codePrinter->increaseLevel();
$rightExpr = new Expression($expression['right']);
@@ -149,7 +157,6 @@ public function compile($expression, CompilationContext $compilationContext)
$statement->compile($compilationContext);
$compilationContext->codePrinter->decreaseLevel();
-
$compilationContext->codePrinter->output('}');
return new CompiledExpression('bool', $flagVariable->getName(), $expression);
diff --git a/Library/Operators/Logical/LogicalBaseOperator.php b/Library/Operators/Logical/LogicalBaseOperator.php
index 8a4d84e763..ca5c8ea0f5 100644
--- a/Library/Operators/Logical/LogicalBaseOperator.php
+++ b/Library/Operators/Logical/LogicalBaseOperator.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Logical;
use Zephir\CompilationContext;
@@ -24,7 +26,7 @@
*/
class LogicalBaseOperator extends BaseOperator
{
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException('Missing left part of the expression', $expression);
@@ -57,13 +59,9 @@ public function compile($expression, CompilationContext $compilationContext)
case 'variable':
$variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression);
switch ($variableRight->getType()) {
- case 'int':
- return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$variableRight->getName().')', $expression);
-
case 'bool':
- return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$variableRight->getName().')', $expression);
-
case 'double':
+ case 'int':
return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$variableRight->getName().')', $expression);
case 'variable':
@@ -94,13 +92,9 @@ public function compile($expression, CompilationContext $compilationContext)
case 'variable':
$variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression);
switch ($variableRight->getType()) {
- case 'int':
- return new CompiledExpression('bool', '('.$left->getBooleanCode().' '.$this->operator.' '.$variableRight->getName().')', $expression);
-
case 'bool':
- return new CompiledExpression('bool', '('.$left->getBooleanCode().' '.$this->operator.' '.$variableRight->getName().')', $expression);
-
case 'double':
+ case 'int':
return new CompiledExpression('bool', '('.$left->getBooleanCode().' '.$this->operator.' '.$variableRight->getName().')', $expression);
case 'variable':
@@ -120,10 +114,8 @@ public function compile($expression, CompilationContext $compilationContext)
break;
case 'double':
switch ($right->getType()) {
- case 'int':
- return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$right->getCode().')', $expression);
-
case 'double':
+ case 'int':
return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$right->getCode().')', $expression);
case 'bool':
@@ -152,13 +144,9 @@ public function compile($expression, CompilationContext $compilationContext)
case 'variable':
$variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']);
switch ($variableRight->getType()) {
- case 'int':
- return new CompiledExpression('bool', '('.$variableLeft->getName().' '.$this->operator.' '.$variableRight->getName().')', $expression);
-
case 'bool':
- return new CompiledExpression('bool', '('.$variableLeft->getName().' '.$this->operator.' '.$variableRight->getName().')', $expression);
-
case 'double':
+ case 'int':
return new CompiledExpression('bool', '('.$variableLeft->getName().' '.$this->operator.' '.$variableRight->getName().')', $expression);
case 'variable':
@@ -212,10 +200,8 @@ public function compile($expression, CompilationContext $compilationContext)
case 'double':
switch ($right->getType()) {
- case 'int':
- return new CompiledExpression('bool', $variableLeft->getName().' '.$this->operator.' '.$right->getCode(), $expression);
-
case 'double':
+ case 'int':
return new CompiledExpression('bool', $variableLeft->getName().' '.$this->operator.' '.$right->getCode(), $expression);
case 'bool':
@@ -251,10 +237,8 @@ public function compile($expression, CompilationContext $compilationContext)
case 'string':
switch ($right->getType()) {
- case 'int':
- return new CompiledExpression('bool', '('.$variableLeft->getName().' && Z_STRLEN_P('.$variableLeft->getName().')) '.$this->operator.' '.$right->getCode(), $expression);
-
case 'double':
+ case 'int':
return new CompiledExpression('bool', '('.$variableLeft->getName().' && Z_STRLEN_P('.$variableLeft->getName().')) '.$this->operator.' '.$right->getCode(), $expression);
case 'bool':
@@ -296,17 +280,8 @@ public function compile($expression, CompilationContext $compilationContext)
switch ($right->getType()) {
/* a && 1 */
case 'int':
- case 'double':
- $compilationContext->headersManager->add('kernel/operators');
- $op = $this->operator;
- $op1 = $variableLeftCode;
- $op2 = $right->getCode();
- $compilationContext->headersManager->add('kernel/operators');
-
- return new CompiledExpression('bool', 'zephir_is_true('.$op1.') '.$op.' '.$op2, $expression);
-
- /* a && 1 */
case 'bool':
+ case 'double':
$compilationContext->headersManager->add('kernel/operators');
$op = $this->operator;
$op1 = $variableLeftCode;
@@ -321,13 +296,9 @@ public function compile($expression, CompilationContext $compilationContext)
$variableRightCode = $compilationContext->backend->getVariableCode($variableRight);
switch ($variableRight->getType()) {
/* a(var) && a(int) */
- case 'int':
- $compilationContext->headersManager->add('kernel/operators');
-
- return new CompiledExpression('bool', 'zephir_is_true('.$variableLeftCode.') '.$this->operator.' '.$variableRightCode, $expression);
-
/* a(var) && a(bool) */
case 'bool':
+ case 'int':
$compilationContext->headersManager->add('kernel/operators');
return new CompiledExpression('bool', 'zephir_is_true('.$variableLeftCode.') '.$this->operator.' '.$variableRightCode, $expression);
diff --git a/Library/Operators/Logical/OrOperator.php b/Library/Operators/Logical/OrOperator.php
index 876576fa50..6e8588e8f1 100644
--- a/Library/Operators/Logical/OrOperator.php
+++ b/Library/Operators/Logical/OrOperator.php
@@ -9,8 +9,11 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Logical;
+use Exception;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
use Zephir\Exception\CompilerException;
@@ -23,14 +26,14 @@ class OrOperator extends LogicalBaseOperator
protected string $bitOperator = '||';
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
- throw new \Exception('Missing left part of the expression');
+ throw new Exception('Missing left part of the expression');
}
if (!isset($expression['right'])) {
- throw new \Exception('Missing right part of the expression');
+ throw new Exception('Missing right part of the expression');
}
$leftExpr = new Expression($expression['left']);
@@ -92,7 +95,6 @@ public function compile($expression, CompilationContext $compilationContext)
$statement->compile($compilationContext);
$compilationContext->codePrinter->output('if (!('.$flagVariable->getName().')) {');
-
$compilationContext->codePrinter->increaseLevel();
$rightExpr = new Expression($expression['right']);
@@ -149,7 +151,6 @@ public function compile($expression, CompilationContext $compilationContext)
$statement->compile($compilationContext);
$compilationContext->codePrinter->decreaseLevel();
-
$compilationContext->codePrinter->output('}');
return new CompiledExpression('bool', $flagVariable->getName(), $expression);
diff --git a/Library/Operators/Other/CastOperator.php b/Library/Operators/Other/CastOperator.php
index cc5e3a582b..c38ab4def1 100644
--- a/Library/Operators/Other/CastOperator.php
+++ b/Library/Operators/Other/CastOperator.php
@@ -53,7 +53,7 @@ public function compile(array $expression, CompilationContext $compilationContex
case Types::T_INT:
switch ($resolved->getType()) {
case Types::T_NULL:
- return new CompiledExpression('int', 0, $expression);
+ return new CompiledExpression('int', '0', $expression);
case Types::T_CHAR:
case Types::T_UCHAR:
@@ -258,7 +258,7 @@ public function compile(array $expression, CompilationContext $compilationContex
case Types::T_DOUBLE:
switch ($resolved->getType()) {
case Types::T_NULL:
- return new CompiledExpression('double', 0, $expression);
+ return new CompiledExpression('double', '0', $expression);
case Types::T_BOOL:
return new CompiledExpression('double', $resolved->getBooleanCode(), $expression);
diff --git a/Library/Operators/Other/CloneOperator.php b/Library/Operators/Other/CloneOperator.php
index bd1a678fc5..b7a8d6c3c6 100644
--- a/Library/Operators/Other/CloneOperator.php
+++ b/Library/Operators/Other/CloneOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -25,14 +28,13 @@
class CloneOperator extends BaseOperator
{
/**
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
$compilationContext->headersManager->add('kernel/object');
@@ -41,12 +43,12 @@ public function compile(array $expression, CompilationContext $compilationContex
$exprVariable->setExpectReturn(true);
$exprCompiledVariable = $exprVariable->compile($compilationContext);
- if ('variable' != $exprCompiledVariable->getType()) {
+ if ('variable' !== $exprCompiledVariable->getType()) {
throw new CompilerException('Expression type: '.$exprCompiledVariable->getType().' cannot be used as array', $expression);
}
$clonedVariable = $compilationContext->symbolTable->getVariableForRead($exprCompiledVariable->getCode(), $compilationContext, $expression);
- if ('variable' != $clonedVariable->getType()) {
+ if ('variable' !== $clonedVariable->getType()) {
throw new CompilerException('Variable type: '.$exprVariable->getType().' cannot be cloned');
}
diff --git a/Library/Operators/Other/ConcatOperator.php b/Library/Operators/Other/ConcatOperator.php
index bc8a8d4edf..620dc2ec81 100644
--- a/Library/Operators/Other/ConcatOperator.php
+++ b/Library/Operators/Other/ConcatOperator.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use function Zephir\add_slashes;
@@ -29,14 +31,14 @@ class ConcatOperator extends BaseOperator
/**
* Performs concat compilation.
*
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
* @return CompiledExpression
*
* @throws CompilerException
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException('Missing left part of the expression', $expression);
@@ -54,9 +56,9 @@ public function compile($expression, CompilationContext $compilationContext)
$optimized = $this->_getOptimizedConcat($expression, $compilationContext, $isFullString);
if (\is_array($optimized)) {
if (!$isFullString) {
- $expected = $this->getExpectedComplexLiteral($compilationContext, $expression);
+ $expected = $this->getExpectedComplexLiteral($compilationContext);
} else {
- $expected = $this->getExpectedComplexLiteral($compilationContext, $expression, 'string');
+ $expected = $this->getExpectedComplexLiteral($compilationContext, 'string');
}
$expected->setDynamicTypes('string');
@@ -87,7 +89,7 @@ public function compile($expression, CompilationContext $compilationContext)
$variableRight = $compilationContext->backend->getVariableCode($variableRight);
}
- $expected = $this->getExpectedComplexLiteral($compilationContext, $expression);
+ $expected = $this->getExpectedComplexLiteral($compilationContext);
$expectedCode = $compilationContext->backend->getVariableCode($expected);
if ('string' == $left->getType() && 'variable' == $right->getType()) {
@@ -108,15 +110,15 @@ public function compile($expression, CompilationContext $compilationContext)
}
/**
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
- * @param bool $isFullString
+ * @param bool $isFullString
*
* @return array
*
* @throws CompilerException
*/
- private function _getOptimizedConcat($expression, CompilationContext $compilationContext, &$isFullString)
+ private function _getOptimizedConcat(array $expression, CompilationContext $compilationContext, &$isFullString): array
{
$originalExpr = $expression;
$isFullString = true;
@@ -261,7 +263,7 @@ private function _getOptimizedConcat($expression, CompilationContext $compilatio
return [$key, implode(', ', $concatParts)];
}
- private function compileExpression(Expression $expression, CompilationContext $context, $type)
+ private function compileExpression(Expression $expression, CompilationContext $context, $type): CompiledExpression
{
try {
switch ($type) {
diff --git a/Library/Operators/Other/EmptyOperator.php b/Library/Operators/Other/EmptyOperator.php
index 78f00b1380..471b7bddab 100644
--- a/Library/Operators/Other/EmptyOperator.php
+++ b/Library/Operators/Other/EmptyOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -25,14 +28,13 @@
class EmptyOperator extends BaseOperator
{
/**
- * @param $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
$compilationContext->headersManager->add('kernel/operators');
diff --git a/Library/Operators/Other/FetchOperator.php b/Library/Operators/Other/FetchOperator.php
index bbd6854aa7..f44bc8a3e3 100644
--- a/Library/Operators/Other/FetchOperator.php
+++ b/Library/Operators/Other/FetchOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -26,14 +29,13 @@
class FetchOperator extends BaseOperator
{
/**
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
$compilationContext->headersManager->add('kernel/array');
@@ -42,11 +44,11 @@ public function compile(array $expression, CompilationContext $compilationContex
throw new CompilerException('Cannot use variable type: '.$variable->gettype().' in "fetch" operator', $expression);
}
- /*
+ /**
* return_value must not be observed
*/
- if ('return_value' != $variable->getName()) {
- /*
+ if ('return_value' !== $variable->getName()) {
+ /**
* TODO: use a read detector here
*/
$readOnly = false;
@@ -73,11 +75,7 @@ public function compile(array $expression, CompilationContext $compilationContex
$variable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext);
}
- if ($readOnly) {
- $flags = '1';
- } else {
- $flags = '0';
- }
+ $flags = $readOnly ? '1' : '0';
switch ($expression['right']['type']) {
case 'array-access':
diff --git a/Library/Operators/Other/InstanceOfOperator.php b/Library/Operators/Other/InstanceOfOperator.php
index a0c9f7c003..1567dfc743 100644
--- a/Library/Operators/Other/InstanceOfOperator.php
+++ b/Library/Operators/Other/InstanceOfOperator.php
@@ -9,16 +9,21 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
+use ReflectionException;
+use Zephir\Classes\Entry;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
-use function Zephir\escape_class;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
-use function Zephir\fqcn;
use Zephir\Operators\BaseOperator;
+use function Zephir\escape_class;
+
/**
* InstanceOf.
*
@@ -30,12 +35,11 @@ class InstanceOfOperator extends BaseOperator
* @param $expression
* @param CompilationContext $context
*
- * @throws CompilerException
- * @throws \Zephir\Exception
- *
* @return CompiledExpression
+ * @throws Exception
+ * @throws ReflectionException
*/
- public function compile($expression, CompilationContext $context)
+ public function compile($expression, CompilationContext $context): CompiledExpression
{
$left = new Expression($expression['left']);
$resolved = $left->compile($context);
@@ -55,26 +59,12 @@ public function compile($expression, CompilationContext $context)
switch ($resolved->getType()) {
case 'string':
- $className = fqcn($resolvedVariable, $context->classDefinition->getNamespace(), $context->aliasManager);
-
- if ($context->compiler->isClass($className)) {
- $classDefinition = $context->compiler->getClassDefinition($className);
- $classEntry = $classDefinition->getClassEntry($context);
- } else {
- if (!class_exists($className, false)) {
- $code = 'SL("'.$resolvedVariable.'")';
- } else {
- $classEntry = $context->classDefinition->getClassEntryByClassName($className, $context, true);
- if (!$classEntry) {
- $code = 'SL("'.$resolvedVariable.'")';
- }
- }
- }
+ $classEntry = (new Entry($resolvedVariable, $context));
break;
default:
switch ($resolved->getType()) {
case 'variable':
- if ('this' == $resolvedVariable) {
+ if ('this' === $resolvedVariable) {
/**
* TODO: It's an optimization variant, but maybe we need to get entry in runtime?
*/
@@ -82,7 +72,7 @@ public function compile($expression, CompilationContext $context)
} elseif (!$context->symbolTable->hasVariable($resolvedVariable)) {
$className = $context->getFullName($resolvedVariable);
- if ('Traversable' == $className) {
+ if ('Traversable' === $className) {
$symbol = $context->backend->getVariableCode($symbolVariable);
return new CompiledExpression('bool', 'zephir_zval_is_traversable('.$symbol.')', $expression);
@@ -99,8 +89,10 @@ public function compile($expression, CompilationContext $context)
if (!class_exists($className, false)) {
$code = 'SL("'.trim(escape_class($className), '\\').'")';
} else {
- $classEntry = $context->classDefinition->getClassEntryByClassName($className, $context, true);
- if (!$classEntry) {
+ $entry = (new Entry($resolvedVariable, $context));
+ $classEntry = $entry->get();
+
+ if (!$entry->isInternal()) {
$code = 'SL("'.trim(escape_class($className), '\\').'")';
}
}
@@ -136,7 +128,7 @@ public function compile($expression, CompilationContext $context)
return new CompiledExpression('bool', 'zephir_instance_of_ev('.$symbol.', '.$classEntry.')', $expression);
}
- private function prepareBackendSpecificCode($variable, CompilationContext $context)
+ private function prepareBackendSpecificCode($variable, CompilationContext $context): string
{
return strtr('Z_STRVAL_P(:p:name), Z_STRLEN_P(:p:name)', [
':name' => $variable,
diff --git a/Library/Operators/Other/IssetOperator.php b/Library/Operators/Other/IssetOperator.php
index 1a4a795bc8..45dbd814d2 100644
--- a/Library/Operators/Other/IssetOperator.php
+++ b/Library/Operators/Other/IssetOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -27,16 +30,15 @@ class IssetOperator extends BaseOperator
/**
* Compiles an 'isset' operator.
*
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
- if ('list' == $expression['left']['type']) {
+ if ('list' === $expression['left']['type']) {
$left = $expression['left']['left'];
} else {
$left = $expression['left'];
diff --git a/Library/Operators/Other/LikelyOperator.php b/Library/Operators/Other/LikelyOperator.php
index feac274f77..679b001bbd 100644
--- a/Library/Operators/Other/LikelyOperator.php
+++ b/Library/Operators/Other/LikelyOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -25,14 +28,13 @@
class LikelyOperator extends BaseOperator
{
/**
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'likely' expression", $expression['left']);
@@ -42,11 +44,11 @@ public function compile(array $expression, CompilationContext $compilationContex
$leftExpr->setReadOnly(true);
$left = $leftExpr->compile($compilationContext);
- if ('bool' == $left->getType()) {
+ if ('bool' === $left->getType()) {
return new CompiledExpression('bool', 'EXPECTED('.$left->getCode().')', $expression);
}
- if ('variable' == $left->getType()) {
+ if ('variable' === $left->getType()) {
$variable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']);
switch ($variable->getType()) {
case 'bool':
diff --git a/Library/Operators/Other/NewInstanceOperator.php b/Library/Operators/Other/NewInstanceOperator.php
index 069b8db91f..3081c2d520 100644
--- a/Library/Operators/Other/NewInstanceOperator.php
+++ b/Library/Operators/Other/NewInstanceOperator.php
@@ -9,10 +9,16 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
+use ReflectionClass;
+use ReflectionException;
+use Zephir\Classes\Entry;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\MethodCall;
@@ -32,18 +38,18 @@ class NewInstanceOperator extends BaseOperator
/**
* Creates a new instance.
*
- * @param $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws ReflectionException
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
$codePrinter = $compilationContext->codePrinter;
- /*
+ /**
* Resolves the symbol that expects the value
*/
$this->literalOnly = false;
@@ -56,7 +62,7 @@ public function compile(array $expression, CompilationContext $compilationContex
throw new CompilerException('Cannot use non-heap variable to store new instance', $expression);
}
- if ('return_value' != $symbolVariable->getName()) {
+ if ('return_value' !== $symbolVariable->getName()) {
if ($symbolVariable->hasDifferentDynamicType(['unknown', 'undefined', 'object', 'null'])) {
$compilationContext->logger->warning(
'Possible attempt to use non-object in "new" operator',
@@ -65,7 +71,7 @@ public function compile(array $expression, CompilationContext $compilationContex
}
}
- /*
+ /**
* Mark variables as dynamic objects
*/
$symbolVariable->setDynamicTypes('object');
@@ -104,7 +110,7 @@ public function compile(array $expression, CompilationContext $compilationContex
$classDefinition = $compilationContext->compiler->getClassDefinition($className);
}
- /*
+ /**
* Classes inside the same extension
*/
if ($classDefinition) {
@@ -112,7 +118,7 @@ public function compile(array $expression, CompilationContext $compilationContex
$symbolVariable->setClassTypes($className);
$symbolVariable->setAssociatedClass($classDefinition);
} else {
- /*
+ /**
* Classes outside the extension
*/
if ($dynamic) {
@@ -121,7 +127,7 @@ public function compile(array $expression, CompilationContext $compilationContex
throw new CompilerException('Only dynamic/string variables can be used in new operator. '.$classNameVariable->getName(), $expression);
}
- /*
+ /**
* Use a safe string version of the variable to avoid segfaults
*/
$compilationContext->headersManager->add('kernel/object');
@@ -153,39 +159,32 @@ public function compile(array $expression, CompilationContext $compilationContex
$zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext);
$classEntry = $zendClassEntry->getName();
} else {
- $reflectionClass = new \ReflectionClass($className);
+ $reflectionClass = new ReflectionClass($className);
if ($reflectionClass->isInterface()) {
throw new CompilerException('Interfaces cannot be instantiated', $expression);
- } else {
- if (method_exists($reflectionClass, 'isTrait')) {
- if ($reflectionClass->isTrait()) {
- throw new CompilerException('Traits cannot be instantiated', $expression);
- }
- }
}
- $classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, $compilationContext, true);
- if (!$classEntry) {
- $classNameToFetch = 'SL("'.escape_class($className).'")';
- $zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext);
- $classEntry = $zendClassEntry->getName();
- } else {
- $symbolVariable->setAssociatedClass($reflectionClass);
+ if (method_exists($reflectionClass, 'isTrait') && $reflectionClass->isTrait()) {
+ throw new CompilerException('Traits cannot be instantiated', $expression);
}
+
+ $classEntry = (new Entry($expression['class'], $compilationContext))->get();
+ $symbolVariable->setAssociatedClass($reflectionClass);
}
$symbolVariable->setClassTypes($className);
}
+
$compilationContext->backend->initObject($symbolVariable, $classEntry, $compilationContext);
}
}
- /*
+ /**
* Mark variable initialized
*/
$symbolVariable->setIsInitialized(true, $compilationContext);
- /*
+ /**
* Don't check the constructor for stdclass instances
*/
if ($isStdClass) {
@@ -237,7 +236,7 @@ public function compile(array $expression, CompilationContext $compilationContex
]);
}
- /*
+ /**
* If we are certain that there is a constructor we call it, otherwise we checked it at runtime.
*/
if ($callConstructor) {
diff --git a/Library/Operators/Other/NewInstanceTypeOperator.php b/Library/Operators/Other/NewInstanceTypeOperator.php
index 3fa30139ab..d949ddf0ce 100644
--- a/Library/Operators/Other/NewInstanceTypeOperator.php
+++ b/Library/Operators/Other/NewInstanceTypeOperator.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\Builder\FunctionCallBuilder;
@@ -32,14 +34,13 @@ class NewInstanceTypeOperator extends BaseOperator
/**
* Executes the operator.
*
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws CompilerException
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['parameters'])) {
throw new CompilerException("Invalid 'parameters' for new-type", $expression);
diff --git a/Library/Operators/Other/RangeExclusiveOperator.php b/Library/Operators/Other/RangeExclusiveOperator.php
index be24288e61..c4f5e7bcea 100644
--- a/Library/Operators/Other/RangeExclusiveOperator.php
+++ b/Library/Operators/Other/RangeExclusiveOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Expression\Builder\BuilderFactory;
@@ -26,14 +29,13 @@
class RangeExclusiveOperator extends BaseOperator
{
/**
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']);
diff --git a/Library/Operators/Other/RangeInclusiveOperator.php b/Library/Operators/Other/RangeInclusiveOperator.php
index 689e107e55..72ad8419b3 100644
--- a/Library/Operators/Other/RangeInclusiveOperator.php
+++ b/Library/Operators/Other/RangeInclusiveOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -26,14 +29,13 @@
class RangeInclusiveOperator extends BaseOperator
{
/**
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']);
diff --git a/Library/Operators/Other/RequireOperator.php b/Library/Operators/Other/RequireOperator.php
index 6576678566..9103b472ab 100644
--- a/Library/Operators/Other/RequireOperator.php
+++ b/Library/Operators/Other/RequireOperator.php
@@ -9,11 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
-use Zephir\Exception\CompilerException;
+use Zephir\Exception;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -25,24 +27,23 @@
class RequireOperator extends BaseOperator
{
/**
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
$expr = new Expression($expression['left']);
$expr->setReadOnly(true);
$expr->setExpectReturn(true);
$exprPath = $expr->compile($compilationContext);
- if ('variable' == $exprPath->getType()) {
+ if ('variable' === $exprPath->getType()) {
$exprVariable = $compilationContext->symbolTable->getVariableForRead($exprPath->getCode(), $compilationContext, $expression);
$exprVar = $compilationContext->backend->getVariableCode($exprVariable);
- if ('variable' == $exprVariable->getType()) {
+ if ('variable' === $exprVariable->getType()) {
if ($exprVariable->hasDifferentDynamicType(['undefined', 'string'])) {
$compilationContext->logger->warning(
'Possible attempt to use invalid type as path in "require" operator',
diff --git a/Library/Operators/Other/ShortTernaryOperator.php b/Library/Operators/Other/ShortTernaryOperator.php
index 408d080ca4..9714649691 100644
--- a/Library/Operators/Other/ShortTernaryOperator.php
+++ b/Library/Operators/Other/ShortTernaryOperator.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\Builder\Operators\UnaryOperatorBuilder;
@@ -37,9 +39,9 @@ class ShortTernaryOperator extends BaseOperator
*
* @return CompiledExpression
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
- /*
+ /**
* This variable is used to check if the compound and expression is evaluated as true or false:
* Ensure that newly allocated variables are local-only (setReadOnly)
*/
@@ -61,7 +63,7 @@ public function compile($expression, CompilationContext $compilationContext)
$expression['left']
),
new StatementsBlockBuilder([
- /*
+ /**
* Create an implicit 'let' operation to update the evaluated right operator
*/
new LetStatementBuilder([
@@ -75,7 +77,7 @@ public function compile($expression, CompilationContext $compilationContext)
], $expression['extra']),
]),
new StatementsBlockBuilder([
- /*
+ /**
* Create an implicit 'let' operation to update the evaluated right operator
*/
new LetStatementBuilder([
diff --git a/Library/Operators/Other/TernaryOperator.php b/Library/Operators/Other/TernaryOperator.php
index 799b78ca28..561492aac6 100644
--- a/Library/Operators/Other/TernaryOperator.php
+++ b/Library/Operators/Other/TernaryOperator.php
@@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
@@ -32,9 +34,9 @@ class TernaryOperator extends BaseOperator
*
* @return CompiledExpression
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
- /*
+ /**
* This variable is used to check if the compound and expression is evaluated as true or false:
* Ensure that newly allocated variables are local-only (setReadOnly)
*/
diff --git a/Library/Operators/Other/TypeHintOperator.php b/Library/Operators/Other/TypeHintOperator.php
index ef02d6396d..b53c37b027 100644
--- a/Library/Operators/Other/TypeHintOperator.php
+++ b/Library/Operators/Other/TypeHintOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -37,14 +40,13 @@ public function setStrict($strict)
/**
* Performs type-hint compilation.
*
- * @param array $expression
+ * @param array $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile(array $expression, CompilationContext $compilationContext)
+ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
$expr = new Expression($expression['right']);
$expr->setReadOnly(true);
diff --git a/Library/Operators/Other/TypeOfOperator.php b/Library/Operators/Other/TypeOfOperator.php
index 3cb77553f5..29120ecfd5 100644
--- a/Library/Operators/Other/TypeOfOperator.php
+++ b/Library/Operators/Other/TypeOfOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Expression\Builder\BuilderFactory;
@@ -29,11 +32,10 @@ class TypeOfOperator extends BaseOperator
* @param $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
- * @return bool|CompiledExpression
+ * @return CompiledExpression
+ * @throws Exception
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'typeof' expression", $expression['left']);
diff --git a/Library/Operators/Other/UnlikelyOperator.php b/Library/Operators/Other/UnlikelyOperator.php
index 87dd58f3b2..cdef007d3a 100644
--- a/Library/Operators/Other/UnlikelyOperator.php
+++ b/Library/Operators/Other/UnlikelyOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Other;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -30,9 +33,9 @@ class UnlikelyOperator extends BaseOperator
* @param $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
- * @throws CompilerException
+ * @throws Exception
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'unlikely' expression", $expression['left']);
@@ -42,11 +45,11 @@ public function compile($expression, CompilationContext $compilationContext)
$leftExpr->setReadOnly(true);
$left = $leftExpr->compile($compilationContext);
- if ('bool' == $left->getType()) {
+ if ('bool' === $left->getType()) {
return new CompiledExpression('bool', 'UNEXPECTED('.$left->getCode().')', $expression);
}
- if ('variable' == $left->getType()) {
+ if ('variable' === $left->getType()) {
$variable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']);
switch ($variable->getType()) {
case 'bool':
diff --git a/Library/Operators/Unary/MinusOperator.php b/Library/Operators/Unary/MinusOperator.php
index 5e4f09599f..2d2e74d311 100644
--- a/Library/Operators/Unary/MinusOperator.php
+++ b/Library/Operators/Unary/MinusOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Unary;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -25,11 +28,10 @@ class MinusOperator extends BaseOperator
* @param $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException('Missing left part of the expression');
diff --git a/Library/Operators/Unary/NotOperator.php b/Library/Operators/Unary/NotOperator.php
index dd756ed395..04e05a983c 100644
--- a/Library/Operators/Unary/NotOperator.php
+++ b/Library/Operators/Unary/NotOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Unary;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -23,11 +26,10 @@ class NotOperator extends BaseOperator
* @param $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException('Missing left part of the expression', $expression);
diff --git a/Library/Operators/Unary/PlusOperator.php b/Library/Operators/Unary/PlusOperator.php
index 90d25a85fa..472589acc7 100644
--- a/Library/Operators/Unary/PlusOperator.php
+++ b/Library/Operators/Unary/PlusOperator.php
@@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Operators\Unary;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
+use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;
@@ -25,11 +28,10 @@ class PlusOperator extends BaseOperator
* @param $expression
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
- *
* @return CompiledExpression
+ * @throws Exception
*/
- public function compile($expression, CompilationContext $compilationContext)
+ public function compile($expression, CompilationContext $compilationContext): CompiledExpression
{
if (!isset($expression['left'])) {
throw new CompilerException('Missing left part of the expression');
diff --git a/Library/Statements/ThrowStatement.php b/Library/Statements/ThrowStatement.php
index 61add0b163..70a7e38322 100644
--- a/Library/Statements/ThrowStatement.php
+++ b/Library/Statements/ThrowStatement.php
@@ -9,15 +9,21 @@
* the LICENSE file that was distributed with this source code.
*/
+declare(strict_types=1);
+
namespace Zephir\Statements;
-use function Zephir\add_slashes;
+use ReflectionException;
+use Zephir\Classes\Entry;
use Zephir\CodePrinter;
use Zephir\CompilationContext;
use Zephir\Compiler;
use Zephir\Exception;
use Zephir\Exception\CompilerException;
use Zephir\Expression;
+
+use function in_array;
+use function Zephir\add_slashes;
use function Zephir\fqcn;
/**
@@ -30,7 +36,8 @@ class ThrowStatement extends StatementAbstract
/**
* @param CompilationContext $compilationContext
*
- * @throws CompilerException
+ * @throws Exception
+ * @throws ReflectionException
*/
public function compile(CompilationContext $compilationContext)
{
@@ -68,25 +75,16 @@ public function compile(CompilationContext $compilationContext)
}
} else {
if ($compilationContext->compiler->isBundledClass($className)) {
- $classEntry = $compilationContext->classDefinition->getClassEntryByClassName(
- $className,
- $compilationContext,
- true
- );
- if ($classEntry) {
- $message = $expr['parameters'][0]['parameter']['value'];
- $this->throwStringException($codePrinter, $classEntry, $message, $expr);
-
- return;
- }
+ $classEntry = (new Entry($expr['class'], $compilationContext))->get();
+ $message = $expr['parameters'][0]['parameter']['value'];
+ $this->throwStringException($codePrinter, $classEntry, $message, $expr);
+
+ return;
}
}
} else {
- if (\in_array($expr['type'], ['string', 'char', 'int', 'double'])) {
- $class = $compilationContext->classDefinition->getClassEntryByClassName(
- 'Exception',
- $compilationContext
- );
+ if (in_array($expr['type'], ['string', 'char', 'int', 'double'])) {
+ $class = (new Entry('Exception', $compilationContext))->get();
$this->throwStringException($codePrinter, $class, $expr['value'], $expr);
@@ -102,7 +100,7 @@ public function compile(CompilationContext $compilationContext)
throw new CompilerException($e->getMessage(), $expr, $e->getCode(), $e);
}
- if (!\in_array($resolvedExpr->getType(), ['variable', 'string'])) {
+ if (!in_array($resolvedExpr->getType(), ['variable', 'string'])) {
throw new CompilerException(
"Expression '".$resolvedExpr->getType().'" cannot be used as exception',
$expr
@@ -115,7 +113,7 @@ public function compile(CompilationContext $compilationContext)
$expr
);
- if (!\in_array($variableVariable->getType(), ['variable', 'string'])) {
+ if (!in_array($variableVariable->getType(), ['variable', 'string'])) {
throw new CompilerException(
"Variable '".$variableVariable->getType()."' cannot be used as exception",
$expr
@@ -151,7 +149,7 @@ public function compile(CompilationContext $compilationContext)
* @param string $message
* @param array $expression
*/
- private function throwStringException(CodePrinter $printer, $class, $message, $expression)
+ private function throwStringException(CodePrinter $printer, string $class, string $message, array $expression): void
{
$message = add_slashes($message);
$path = Compiler::getShortUserPath($expression['file']);
diff --git a/Library/Zephir.php b/Library/Zephir.php
index 34ef7d883d..c028edfc65 100644
--- a/Library/Zephir.php
+++ b/Library/Zephir.php
@@ -16,9 +16,9 @@
*/
final class Zephir
{
- const VERSION = '0.13.5-$Id$';
+ public const VERSION = '0.14.0-beta.1-$Id$';
- const LOGO = <<<'ASCII'
+ public const LOGO = <<<'ASCII'
_____ __ _
/__ / ___ ____ / /_ (_)____
/ / / _ \/ __ \/ __ \/ / ___/
diff --git a/composer.lock b/composer.lock
index af8c93e42b..db33f7d734 100644
--- a/composer.lock
+++ b/composer.lock
@@ -207,16 +207,16 @@
},
{
"name": "league/flysystem",
- "version": "2.0.5",
+ "version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
- "reference": "27ea64cc9d61ae7b6a5f04bebf062d89dd18e8f7"
+ "reference": "a3c694de9f7e844b76f9d1b61296ebf6e8d89d74"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/27ea64cc9d61ae7b6a5f04bebf062d89dd18e8f7",
- "reference": "27ea64cc9d61ae7b6a5f04bebf062d89dd18e8f7",
+ "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/a3c694de9f7e844b76f9d1b61296ebf6e8d89d74",
+ "reference": "a3c694de9f7e844b76f9d1b61296ebf6e8d89d74",
"shasum": ""
},
"require": {
@@ -237,7 +237,8 @@
"google/cloud-storage": "^1.23",
"phpseclib/phpseclib": "^2.0",
"phpstan/phpstan": "^0.12.26",
- "phpunit/phpunit": "^8.5 || ^9.4"
+ "phpunit/phpunit": "^8.5 || ^9.4",
+ "sabre/dav": "^4.1"
},
"type": "library",
"autoload": {
@@ -271,7 +272,7 @@
],
"support": {
"issues": "https://github.com/thephpleague/flysystem/issues",
- "source": "https://github.com/thephpleague/flysystem/tree/2.0.5"
+ "source": "https://github.com/thephpleague/flysystem/tree/2.1.1"
},
"funding": [
{
@@ -287,7 +288,7 @@
"type": "tidelift"
}
],
- "time": "2021-04-11T15:03:35+00:00"
+ "time": "2021-06-23T22:07:10+00:00"
},
{
"name": "league/mime-type-detection",
@@ -5233,5 +5234,5 @@
"ext-pdo_sqlite": "*",
"ext-zip": "*"
},
- "plugin-api-version": "2.0.0"
+ "plugin-api-version": "2.1.0"
}
diff --git a/config/class-entries.php b/config/class-entries.php
new file mode 100644
index 0000000000..837819d1af
--- /dev/null
+++ b/config/class-entries.php
@@ -0,0 +1,138 @@
+
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+/**
+ * PHP Class Name => [Zend Class Entry, header-file-path (optional)]
+ */
+return [
+ /**
+ * SPL
+ */
+ 'ArrayObject' => ['spl_ce_ArrayObject', 'ext/spl/spl_array'],
+ 'ArrayIterator' => ['spl_ce_ArrayIterator', 'ext/spl/spl_array'],
+ 'RecursiveArrayIterator' => ['spl_ce_RecursiveArrayIterator', 'ext/spl/spl_array'],
+
+ 'SplFileInfo' => ['spl_ce_SplFileInfo', 'ext/spl/spl_directory'],
+ 'DirectoryIterator' => ['spl_ce_DirectoryIterator', 'ext/spl/spl_directory'],
+ 'FilesystemIterator' => ['spl_ce_FilesystemIterator', 'ext/spl/spl_directory'],
+ 'RecursiveDirectoryIterator' => ['spl_ce_RecursiveDirectoryIterator', 'ext/spl/spl_directory'],
+ 'GlobIterator' => ['spl_ce_GlobIterator', 'ext/spl/spl_directory'],
+ 'SplFileObject' => ['spl_ce_SplFileObject', 'ext/spl/spl_directory'],
+ 'SplTempFileObject' => ['spl_ce_SplTempFileObject', 'ext/spl/spl_directory'],
+
+ 'SplDoublyLinkedList' => ['spl_ce_SplDoublyLinkedList', 'ext/spl/spl_dllist'],
+ 'SplQueue' => ['spl_ce_SplQueue', 'ext/spl/spl_dllist'],
+ 'SplStack' => ['spl_ce_SplStack', 'ext/spl/spl_dllist'],
+
+ 'LogicException' => ['spl_ce_LogicException', 'ext/spl/spl_exceptions'],
+ 'BadFunctionCallException' => ['spl_ce_BadFunctionCallException', 'ext/spl/spl_exceptions'],
+ 'BadMethodCallException' => ['spl_ce_BadMethodCallException', 'ext/spl/spl_exceptions'],
+ 'DomainException' => ['spl_ce_DomainException', 'ext/spl/spl_exceptions'],
+ 'InvalidArgumentException' => ['spl_ce_InvalidArgumentException', 'ext/spl/spl_exceptions'],
+ 'LengthException' => ['spl_ce_LengthException', 'ext/spl/spl_exceptions'],
+ 'OutOfRangeException' => ['spl_ce_OutOfRangeException', 'ext/spl/spl_exceptions'],
+ 'RuntimeException' => ['spl_ce_RuntimeException', 'ext/spl/spl_exceptions'],
+ 'OutOfBoundsException' => ['spl_ce_OutOfBoundsException', 'ext/spl/spl_exceptions'],
+ 'OverflowException' => ['spl_ce_OverflowException', 'ext/spl/spl_exceptions'],
+ 'RangeException' => ['spl_ce_RangeException', 'ext/spl/spl_exceptions'],
+ 'UnderflowException' => ['spl_ce_UnderflowException', 'ext/spl/spl_exceptions'],
+ 'UnexpectedValueException' => ['spl_ce_UnexpectedValueException', 'ext/spl/spl_exceptions'],
+
+ 'SplFixedArray' => ['spl_ce_SplFixedArray', 'ext/spl/spl_fixedarray'],
+
+ 'SplHeap' => ['spl_ce_SplHeap', 'ext/spl/spl_heap'],
+ 'SplMinHeap' => ['spl_ce_SplMinHeap', 'ext/spl/spl_heap'],
+ 'SplMaxHeap' => ['spl_ce_SplMaxHeap', 'ext/spl/spl_heap'],
+ 'SplPriorityQueue' => ['spl_ce_SplPriorityQueue', 'ext/spl/spl_heap'],
+
+ 'AppendIterator' => ['spl_ce_AppendIterator', 'ext/spl/spl_iterators'],
+ 'CachingIterator' => ['spl_ce_CachingIterator', 'ext/spl/spl_iterators'],
+ 'CallbackFilterIterator' => ['spl_ce_CallbackFilterIterator', 'ext/spl/spl_iterators'],
+ 'EmptyIterator' => ['spl_ce_EmptyIterator', 'ext/spl/spl_iterators'],
+ 'FilterIterator' => ['spl_ce_FilterIterator', 'ext/spl/spl_iterators'],
+ 'InfiniteIterator' => ['spl_ce_InfiniteIterator', 'ext/spl/spl_iterators'],
+ 'IteratorIterator' => ['spl_ce_IteratorIterator', 'ext/spl/spl_iterators'],
+ 'LimitIterator' => ['spl_ce_LimitIterator', 'ext/spl/spl_iterators'],
+ 'NoRewindIterator' => ['spl_ce_NoRewindIterator', 'ext/spl/spl_iterators'],
+ 'OuterIterator' => ['spl_ce_OuterIterator', 'ext/spl/spl_iterators'],
+ 'ParentIterator' => ['spl_ce_ParentIterator', 'ext/spl/spl_iterators'],
+ 'RecursiveCachingIterator' => ['spl_ce_RecursiveCachingIterator', 'ext/spl/spl_iterators'],
+ 'RecursiveCallbackFilterIterator' => ['spl_ce_RecursiveCallbackFilterIterator', 'ext/spl/spl_iterators'],
+ 'RecursiveFilterIterator' => ['spl_ce_RecursiveFilterIterator', 'ext/spl/spl_iterators'],
+ 'RecursiveIterator' => ['spl_ce_RecursiveIterator', 'ext/spl/spl_iterators'],
+ 'RecursiveIteratorIterator' => ['spl_ce_RecursiveIteratorIterator', 'ext/spl/spl_iterators'],
+ 'RecursiveRegexIterator' => ['spl_ce_RecursiveRegexIterator', 'ext/spl/spl_iterators'],
+ 'RecursiveTreeIterator' => ['spl_ce_RecursiveTreeIterator', 'ext/spl/spl_iterators'],
+ 'RegexIterator' => ['spl_ce_RegexIterator', 'ext/spl/spl_iterators'],
+ 'SeekableIterator' => ['spl_ce_SeekableIterator', 'ext/spl/spl_iterators'],
+
+ 'SplObserver' => ['spl_ce_SplObserver', 'ext/spl/spl_observer'],
+ 'SplSubject' => ['spl_ce_SplSubject', 'ext/spl/spl_observer'],
+ 'SplObjectStorage' => ['spl_ce_SplObjectStorage', 'ext/spl/spl_observer'],
+ 'MultipleIterator' => ['spl_ce_MultipleIterator', 'ext/spl/spl_observer'],
+
+ /**
+ * Session
+ */
+ 'SessionHandlerInterface' => ['php_session_iface_entry', 'ext/session/php_session'],
+
+ /**
+ * Date
+ */
+ 'DateTimeInterface' => ['php_date_get_interface_ce()', 'ext/date/php_date'],
+ 'DateTime' => ['php_date_get_date_ce()', 'ext/date/php_date'],
+ 'DateTimeImmutable' => ['php_date_get_immutable_ce()', 'ext/date/php_date'],
+ 'DateTimezone' => ['php_date_get_timezone_ce()', 'ext/date/php_date'],
+ 'DateInterval' => ['php_date_get_interval_ce()', 'ext/date/php_date'],
+ 'DatePeriod' => ['php_date_get_period_ce()', 'ext/date/php_date'],
+
+ /**
+ * Closures
+ */
+ 'Closure' => ['zend_ce_closure', 'Zend/zend_closures'],
+
+ /**
+ * Zend exceptions
+ */
+ 'Throwable' => ['zend_ce_throwable'],
+ 'Exception' => ['zend_ce_exception'],
+ 'ErrorException' => ['zend_ce_error_exception'],
+ 'Error' => ['zend_ce_error'],
+ 'CompileError' => ['zend_ce_compile_error'],
+ 'ParseError' => ['zend_ce_parse_error'],
+ 'TypeError' => ['zend_ce_type_error'],
+ 'ArgumentCountError' => ['zend_ce_argument_count_error'],
+ 'ValueError' => ['zend_ce_value_error'],
+ 'ArithmeticError' => ['zend_ce_arithmetic_error'],
+ 'DivisionByZeroError' => ['zend_ce_division_by_zero_error'],
+ 'UnhandledMatchError' => ['zend_ce_unhandled_match_error'],
+
+ /**
+ * Zend interfaces (Zend/zend_interfaces.h)
+ */
+ 'Traversable' => ['zend_ce_traversable'],
+ 'IteratorAggregate' => ['zend_ce_aggregate'],
+ 'Iterator' => ['zend_ce_iterator'],
+ 'ArrayAccess' => ['zend_ce_arrayaccess'],
+ 'Serializable' => ['zend_ce_serializable'],
+ 'Countable' => ['zend_ce_countable'],
+ 'Stringable' => ['zend_ce_stringable'],
+
+ /**
+ * PDO
+ */
+ 'PDO' => ['php_pdo_get_dbh_ce()', 'ext/pdo/php_pdo_driver'],
+ 'PDOException' => ['php_pdo_get_exception()', 'ext/pdo/php_pdo_driver'],
+
+ 'stdClass' => ['zend_standard_class_def'],
+];
diff --git a/ext/php_stub.h b/ext/php_stub.h
index c63f94780f..97666a966f 100644
--- a/ext/php_stub.h
+++ b/ext/php_stub.h
@@ -14,7 +14,7 @@
#define PHP_STUB_VERSION "1.0.0"
#define PHP_STUB_EXTNAME "stub"
#define PHP_STUB_AUTHOR "Phalcon Team and contributors"
-#define PHP_STUB_ZEPVERSION "0.13.5-$Id$"
+#define PHP_STUB_ZEPVERSION "0.14.0-beta.1-$Id$"
#define PHP_STUB_DESCRIPTION "Description test for
Test Extension."
typedef struct _zephir_struct_db {
diff --git a/ext/stub/builtin/stringmethods.zep.c b/ext/stub/builtin/stringmethods.zep.c
index d245564602..d8cd136fa0 100644
--- a/ext/stub/builtin/stringmethods.zep.c
+++ b/ext/stub/builtin/stringmethods.zep.c
@@ -43,7 +43,7 @@ PHP_METHOD(Stub_BuiltIn_StringMethods, camelize)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(str)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(delimiter)
+ Z_PARAM_ZVAL_OR_NULL(delimiter)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -78,7 +78,7 @@ PHP_METHOD(Stub_BuiltIn_StringMethods, uncamelize)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(str)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(delimiter)
+ Z_PARAM_ZVAL_OR_NULL(delimiter)
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/exceptions.zep.c b/ext/stub/exceptions.zep.c
index 6376875494..bf6aea1eb3 100644
--- a/ext/stub/exceptions.zep.c
+++ b/ext/stub/exceptions.zep.c
@@ -183,19 +183,19 @@ PHP_METHOD(Stub_Exceptions, testExceptionLiteral)
do {
if (ZEPHIR_IS_STRING(&type, "string")) {
- ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "Test", "stub/exceptions.zep", 56);
+ ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "Test", "stub/exceptions.zep", 56);
return;
}
if (ZEPHIR_IS_STRING(&type, "char")) {
- ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "t", "stub/exceptions.zep", 58);
+ ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "t", "stub/exceptions.zep", 58);
return;
}
if (ZEPHIR_IS_STRING(&type, "int")) {
- ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "123", "stub/exceptions.zep", 60);
+ ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "123", "stub/exceptions.zep", 60);
return;
}
if (ZEPHIR_IS_STRING(&type, "double")) {
- ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "123.123", "stub/exceptions.zep", 62);
+ ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "123.123", "stub/exceptions.zep", 62);
return;
}
} while(0);
@@ -293,7 +293,7 @@ PHP_METHOD(Stub_Exceptions, testExceptionRethrow)
ZEPHIR_INIT_VAR(&_0);
ZVAL_OBJ(&_0, EG(exception));
Z_ADDREF_P(&_0);
- if (zephir_instance_of_ev(&_0, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_0, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_0);
zephir_throw_exception_debug(&e, "stub/exceptions.zep", 83);
@@ -369,7 +369,7 @@ PHP_METHOD(Stub_Exceptions, testMultiException)
return;
}
} else {
- if (zephir_instance_of_ev(&_0, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_0, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_0);
_3$$7 = zephir_is_callable(&exc);
@@ -451,7 +451,7 @@ PHP_METHOD(Stub_Exceptions, issue1325)
ZEPHIR_INIT_VAR(&_0);
ZVAL_OBJ(&_0, EG(exception));
Z_ADDREF_P(&_0);
- if (zephir_instance_of_ev(&_0, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_0, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_0);
ZEPHIR_INIT_NVAR(&status);
diff --git a/ext/stub/exitdie.zep.c b/ext/stub/exitdie.zep.c
index 5e2c5a0915..797c1a8a1f 100644
--- a/ext/stub/exitdie.zep.c
+++ b/ext/stub/exitdie.zep.c
@@ -36,7 +36,7 @@ PHP_METHOD(Stub_ExitDie, testExit)
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(param)
+ Z_PARAM_ZVAL_OR_NULL(param)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -65,7 +65,7 @@ PHP_METHOD(Stub_ExitDie, testDie)
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(param)
+ Z_PARAM_ZVAL_OR_NULL(param)
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/extendedinterface.zep.c b/ext/stub/extendedinterface.zep.c
index 8b2f0d5efb..e0f49d2865 100644
--- a/ext/stub/extendedinterface.zep.c
+++ b/ext/stub/extendedinterface.zep.c
@@ -16,7 +16,7 @@ ZEPHIR_INIT_CLASS(Stub_ExtendedInterface)
{
ZEPHIR_REGISTER_INTERFACE(Stub, ExtendedInterface, stub, extendedinterface, NULL);
- zend_class_implements(stub_extendedinterface_ce, 1, zephir_get_internal_ce(SL("iteratoraggregate")));
+ zend_class_implements(stub_extendedinterface_ce, 1, zend_ce_aggregate);
zend_class_implements(stub_extendedinterface_ce, 1, zend_ce_countable);
return SUCCESS;
}
diff --git a/ext/stub/fcall.zep.c b/ext/stub/fcall.zep.c
index 42ebc01215..bd943bfbbc 100644
--- a/ext/stub/fcall.zep.c
+++ b/ext/stub/fcall.zep.c
@@ -239,7 +239,7 @@ PHP_METHOD(Stub_Fcall, zvalFcallWith1Parameter)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(callback)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(param1)
+ Z_PARAM_ZVAL_OR_NULL(param1)
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/instance.zep.c b/ext/stub/instance.zep.c
index ab9430513a..e0b503c8da 100644
--- a/ext/stub/instance.zep.c
+++ b/ext/stub/instance.zep.c
@@ -14,7 +14,6 @@
#include "kernel/main.h"
#include "kernel/memory.h"
#include "kernel/object.h"
-#include "ext/spl/spl_array.h"
#include "kernel/array.h"
#include "kernel/fcall.h"
#include "kernel/operators.h"
@@ -50,7 +49,7 @@ PHP_METHOD(Stub_Instance, __construct)
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(11, 11)
Z_PARAM_OBJECT_OF_CLASS(a1, stub_arithmetic_ce)
- Z_PARAM_OBJECT_OF_CLASS(a2, spl_ce_ArrayObject)
+ Z_PARAM_OBJECT_OF_CLASS(a2, stub_arrayobject_ce)
Z_PARAM_OBJECT_OF_CLASS(a3, stub_assign_ce)
Z_PARAM_OBJECT_OF_CLASS(a4, stub_bitwise_ce)
Z_PARAM_OBJECT_OF_CLASS(a5, stub_branchprediction_ce)
diff --git a/ext/stub/instanceoff.zep.c b/ext/stub/instanceoff.zep.c
index c0deb966d4..a13582d99c 100644
--- a/ext/stub/instanceoff.zep.c
+++ b/ext/stub/instanceoff.zep.c
@@ -41,7 +41,7 @@ PHP_METHOD(Stub_Instanceoff, testInstanceOf1)
ZEPHIR_INIT_VAR(&a);
object_init(&a);
- RETURN_MM_BOOL(zephir_instance_of_ev(&a, zend_standard_class_def));
+ RETURN_MM_BOOL(zephir_is_instance_of(&a, SL("stdClass")));
}
PHP_METHOD(Stub_Instanceoff, testInstanceOf2)
diff --git a/ext/stub/mcall.zep.c b/ext/stub/mcall.zep.c
index bf2668595a..4c277c33e6 100644
--- a/ext/stub/mcall.zep.c
+++ b/ext/stub/mcall.zep.c
@@ -828,7 +828,7 @@ PHP_METHOD(Stub_Mcall, optionalParameterVar)
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(param)
+ Z_PARAM_ZVAL_OR_NULL(param)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1217,3 +1217,30 @@ PHP_METHOD(Stub_Mcall, issue1136)
RETURN_CCTOR(&_finfo);
}
+PHP_METHOD(Stub_Mcall, issue2245VarArgumentNullable)
+{
+ zval *param = NULL, param_sub, __$null;
+ zval *this_ptr = getThis();
+
+ ZVAL_UNDEF(¶m_sub);
+ ZVAL_NULL(&__$null);
+#if PHP_VERSION_ID >= 80000
+ bool is_null_true = 1;
+ ZEND_PARSE_PARAMETERS_START(0, 1)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_ZVAL_OR_NULL(param)
+ ZEND_PARSE_PARAMETERS_END();
+#endif
+
+
+ zephir_fetch_params_without_memory_grow(0, 1, ¶m);
+ if (!param) {
+ param = ¶m_sub;
+ param = &__$null;
+ }
+
+
+ RETVAL_ZVAL(param, 1, 0);
+ return;
+}
+
diff --git a/ext/stub/mcall.zep.h b/ext/stub/mcall.zep.h
index 7b2ab78dfb..d3a376be10 100644
--- a/ext/stub/mcall.zep.h
+++ b/ext/stub/mcall.zep.h
@@ -51,6 +51,7 @@ PHP_METHOD(Stub_Mcall, testCallablePass);
PHP_METHOD(Stub_Mcall, testCallableArrayThisMethodPass);
PHP_METHOD(Stub_Mcall, aa);
PHP_METHOD(Stub_Mcall, issue1136);
+PHP_METHOD(Stub_Mcall, issue2245VarArgumentNullable);
ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_mcall_testmethod1, 0, 0, 0)
ZEND_END_ARG_INFO()
@@ -254,6 +255,10 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_mcall_issue1136, 0, 0, 0)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_mcall_issue2245varargumentnullable, 0, 0, 0)
+ ZEND_ARG_INFO(0, param)
+ZEND_END_ARG_INFO()
+
ZEPHIR_INIT_FUNCS(stub_mcall_method_entry) {
#if PHP_VERSION_ID >= 80000
PHP_ME(Stub_Mcall, testMethod1, arginfo_stub_mcall_testmethod1, ZEND_ACC_PUBLIC)
@@ -363,5 +368,6 @@ ZEPHIR_INIT_FUNCS(stub_mcall_method_entry) {
#else
PHP_ME(Stub_Mcall, issue1136, NULL, ZEND_ACC_PUBLIC)
#endif
+ PHP_ME(Stub_Mcall, issue2245VarArgumentNullable, arginfo_stub_mcall_issue2245varargumentnullable, ZEND_ACC_PUBLIC)
PHP_FE_END
};
diff --git a/ext/stub/reflection.zep.c b/ext/stub/reflection.zep.c
index cbb95cba77..8628a8df6e 100644
--- a/ext/stub/reflection.zep.c
+++ b/ext/stub/reflection.zep.c
@@ -75,7 +75,7 @@ PHP_METHOD(Stub_Reflection, setReflectionParameter)
#if PHP_VERSION_ID >= 80000
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(parameter)
+ Z_PARAM_OBJECT_OF_CLASS(parameter, zephir_get_internal_ce(SL("reflectionparameter")))
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/router.zep.c b/ext/stub/router.zep.c
index f9a78747b9..a68201c09a 100644
--- a/ext/stub/router.zep.c
+++ b/ext/stub/router.zep.c
@@ -566,7 +566,7 @@ PHP_METHOD(Stub_Router, handle)
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(uri)
+ Z_PARAM_ZVAL_OR_NULL(uri)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1063,8 +1063,8 @@ PHP_METHOD(Stub_Router, add)
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
- Z_PARAM_ZVAL(httpMethods)
+ Z_PARAM_ZVAL_OR_NULL(paths)
+ Z_PARAM_ZVAL_OR_NULL(httpMethods)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1112,7 +1112,7 @@ PHP_METHOD(Stub_Router, addGet)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1155,7 +1155,7 @@ PHP_METHOD(Stub_Router, addPost)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1198,7 +1198,7 @@ PHP_METHOD(Stub_Router, addPut)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1241,7 +1241,7 @@ PHP_METHOD(Stub_Router, addPatch)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1284,7 +1284,7 @@ PHP_METHOD(Stub_Router, addDelete)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1327,7 +1327,7 @@ PHP_METHOD(Stub_Router, addOptions)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -1370,7 +1370,7 @@ PHP_METHOD(Stub_Router, addHead)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/router/route.zep.c b/ext/stub/router/route.zep.c
index 5edf9c032e..e5f4af8a24 100644
--- a/ext/stub/router/route.zep.c
+++ b/ext/stub/router/route.zep.c
@@ -66,8 +66,8 @@ PHP_METHOD(Stub_Router_Route, __construct)
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
- Z_PARAM_ZVAL(httpMethods)
+ Z_PARAM_ZVAL_OR_NULL(paths)
+ Z_PARAM_ZVAL_OR_NULL(httpMethods)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -498,7 +498,7 @@ PHP_METHOD(Stub_Router_Route, reConfigure)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL(pattern)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(paths)
+ Z_PARAM_ZVAL_OR_NULL(paths)
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/spropertyaccess.zep.c b/ext/stub/spropertyaccess.zep.c
index 66aa4ebc78..a7f504409e 100644
--- a/ext/stub/spropertyaccess.zep.c
+++ b/ext/stub/spropertyaccess.zep.c
@@ -84,7 +84,7 @@ PHP_METHOD(Stub_SPropertyAccess, testArgumentWithUnderscore)
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(delimiter)
+ Z_PARAM_ZVAL_OR_NULL(delimiter)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -120,7 +120,7 @@ PHP_METHOD(Stub_SPropertyAccess, testArgument)
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(delimiter)
+ Z_PARAM_ZVAL_OR_NULL(delimiter)
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/strings.zep.c b/ext/stub/strings.zep.c
index 07cb88b6e7..dc24fee9a2 100644
--- a/ext/stub/strings.zep.c
+++ b/ext/stub/strings.zep.c
@@ -45,7 +45,7 @@ PHP_METHOD(Stub_Strings, camelize)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(str)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(delimiter)
+ Z_PARAM_ZVAL_OR_NULL(delimiter)
ZEND_PARSE_PARAMETERS_END();
#endif
@@ -78,7 +78,7 @@ PHP_METHOD(Stub_Strings, uncamelize)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(str)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(delimiter)
+ Z_PARAM_ZVAL_OR_NULL(delimiter)
ZEND_PARSE_PARAMETERS_END();
#endif
diff --git a/ext/stub/trytest.zep.c b/ext/stub/trytest.zep.c
index 757a5c149f..e71d7dce55 100644
--- a/ext/stub/trytest.zep.c
+++ b/ext/stub/trytest.zep.c
@@ -142,7 +142,7 @@ PHP_METHOD(Stub_TryTest, testTry3)
ZVAL_OBJ(&_2, EG(exception));
Z_ADDREF_P(&_2);
ZEPHIR_INIT_VAR(&_3);
- if (zephir_instance_of_ev(&_2, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_2, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&_3, &_2);
RETURN_MM_STRING("error");
@@ -212,12 +212,12 @@ PHP_METHOD(Stub_TryTest, testTry4)
Z_ADDREF_P(&_4);
ZEPHIR_INIT_VAR(&_5);
ZEPHIR_INIT_VAR(&_6);
- if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) {
+ if (zephir_is_instance_of(&_4, SL("RuntimeException"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&_5, &_4);
RETURN_MM_STRING("domain error");
} else {
- if (zephir_instance_of_ev(&_4, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_4, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&_6, &_4);
RETURN_MM_STRING("error");
@@ -286,12 +286,12 @@ PHP_METHOD(Stub_TryTest, testTry5)
ZVAL_OBJ(&_4, EG(exception));
Z_ADDREF_P(&_4);
ZEPHIR_INIT_VAR(&_5);
- if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) {
+ if (zephir_is_instance_of(&_4, SL("RuntimeException"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&_5, &_4);
RETURN_MM_STRING("any error");
} else {
- if (zephir_instance_of_ev(&_4, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_4, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&_5, &_4);
RETURN_MM_STRING("any error");
@@ -359,12 +359,12 @@ PHP_METHOD(Stub_TryTest, testTry6)
ZEPHIR_INIT_VAR(&_4);
ZVAL_OBJ(&_4, EG(exception));
Z_ADDREF_P(&_4);
- if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) {
+ if (zephir_is_instance_of(&_4, SL("RuntimeException"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_4);
RETURN_MM_STRING("domain error");
} else {
- if (zephir_instance_of_ev(&_4, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_4, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_4);
RETURN_MM_STRING("error");
@@ -432,12 +432,12 @@ PHP_METHOD(Stub_TryTest, testTry7)
ZEPHIR_INIT_VAR(&_4);
ZVAL_OBJ(&_4, EG(exception));
Z_ADDREF_P(&_4);
- if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) {
+ if (zephir_is_instance_of(&_4, SL("RuntimeException"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_4);
RETURN_MM_STRING("any error");
} else {
- if (zephir_instance_of_ev(&_4, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_4, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_4);
RETURN_MM_STRING("any error");
@@ -525,7 +525,7 @@ PHP_METHOD(Stub_TryTest, testTry9)
ZEPHIR_INIT_VAR(&_0);
ZVAL_OBJ(&_0, EG(exception));
Z_ADDREF_P(&_0);
- if (zephir_instance_of_ev(&_0, spl_ce_RuntimeException)) {
+ if (zephir_is_instance_of(&_0, SL("RuntimeException"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_0);
RETURN_MM_STRING("domain error");
@@ -560,7 +560,7 @@ PHP_METHOD(Stub_TryTest, testTry10)
ZEPHIR_INIT_VAR(&_0);
ZVAL_OBJ(&_0, EG(exception));
Z_ADDREF_P(&_0);
- if (zephir_instance_of_ev(&_0, spl_ce_RuntimeException)) {
+ if (zephir_is_instance_of(&_0, SL("RuntimeException"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&e, &_0);
RETURN_MM_STRING("domain error");
@@ -592,7 +592,7 @@ PHP_METHOD(Stub_TryTest, testTry11)
ZEPHIR_INIT_VAR(&_0);
ZVAL_OBJ(&_0, EG(exception));
Z_ADDREF_P(&_0);
- if (zephir_instance_of_ev(&_0, zend_ce_exception)) {
+ if (zephir_is_instance_of(&_0, SL("Exception"))) {
zend_clear_exception();
ZEPHIR_CPY_WRT(&ex, &_0);
}
diff --git a/stub/mcall.zep b/stub/mcall.zep
index e808f5a382..ad6d55ff5d 100644
--- a/stub/mcall.zep
+++ b/stub/mcall.zep
@@ -278,4 +278,9 @@ class Mcall
return _finfo;
}
+
+ public function issue2245VarArgumentNullable(var param = null)
+ {
+ return param;
+ }
}
diff --git a/tests/Extension/MCallTest.php b/tests/Extension/MCallTest.php
index 48b41d80de..fbae3ce479 100644
--- a/tests/Extension/MCallTest.php
+++ b/tests/Extension/MCallTest.php
@@ -166,7 +166,7 @@ private function getReflection()
return $this->reflection;
}
- public function testSouldThrowTypeErrorForOptionalBoolean1(): void
+ public function testShouldThrowTypeErrorForOptionalBoolean1(): void
{
$test = new Mcall();
@@ -205,4 +205,11 @@ public function testIssue1136(): void
$this->assertIsResource($test->issue1136());
}
}
+
+ public function testIssue2245DynamicNullableArgMustBeNullableAsDefault(): void
+ {
+ $test = new Mcall();
+
+ $this->assertNull($test->issue2245VarArgumentNullable());
+ }
}