Skip to content

Commit

Permalink
#2407 - Fix return type
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Oct 29, 2023
1 parent c0ae9c1 commit 0945f04
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions Library/Backend/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,34 +298,30 @@ public function onPostCompile(Method $method, CompilationContext $context): void
}
}

public function generateInitCode(&$groupVariables, $type, $pointer, Variable $variable)
public function generateInitCode(&$groupVariables, $type, $pointer, Variable $variable): ?string
{
$isComplex = \in_array($type, ['variable', 'string', 'array', 'resource', 'callable', 'object', 'mixed'], true);

if ($isComplex && !$variable->isDoublePointer()) {
$groupVariables[] = $variable->getName();
switch ($variable->getRealname()) {
case '__$null':
return "\t".'ZVAL_NULL(&'.$variable->getName().');';
case '__$true':
return "\t".'ZVAL_BOOL(&'.$variable->getName().', 1);';
case '__$false':
return "\t".'ZVAL_BOOL(&'.$variable->getName().', 0);';
default:
return "\t".'ZVAL_UNDEF(&'.$variable->getName().');';
}
return match ($variable->getRealname()) {
'__$null' => "\t" . 'ZVAL_NULL(&' . $variable->getName() . ');',
'__$true' => "\t" . 'ZVAL_BOOL(&' . $variable->getName() . ', 1);',
'__$false' => "\t" . 'ZVAL_BOOL(&' . $variable->getName() . ', 0);',
default => "\t" . 'ZVAL_UNDEF(&' . $variable->getName() . ');',
};
}

if ($variable->isLocalOnly()) {
$groupVariables[] = $variable->getName();

return;
return null;
}

if ($variable->isSuperGlobal()) {
$groupVariables[] = $variable->getName();

return;
return null;
}

if ($variable->isDoublePointer()) {
Expand All @@ -337,7 +333,7 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va
$groupVariables[] = $ptr.$variable->getName();
}

return;
return null;
}

$defaultValue = $variable->getDefaultInitValue();
Expand Down Expand Up @@ -369,16 +365,18 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va
break;
}

return;
return null;
}

if ($variable->mustInitNull() && $pointer) {
$groupVariables[] = $pointer.$variable->getName().' = NULL';

return;
return null;
}

$groupVariables[] = $pointer.$variable->getName();

return null;
}

/**
Expand Down

0 comments on commit 0945f04

Please sign in to comment.