Skip to content

Commit

Permalink
Fixing variadic optional functions generation
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Sep 13, 2018
1 parent f014773 commit 60c6384
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions generated/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
function array_multisort(array &$array1, $array1_sort_order = SORT_ASC, $array1_sort_flags = SORT_REGULAR, ...$params): void
{
error_clear_last();
if ($params !== null) {
$result = \array_multisort($array1, $array1_sort_order, $array1_sort_flags, $params);
if ($params !== []) {
$result = \array_multisort($array1, $array1_sort_order, $array1_sort_flags, ...$params);
} else {
$result = \array_multisort($array1, $array1_sort_order, $array1_sort_flags);
}
Expand Down
4 changes: 2 additions & 2 deletions generated/funchand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function func_get_arg(int $arg_num)
function register_tick_function(callable $function, $arg = null, ...$params): void
{
error_clear_last();
if ($params !== null) {
$result = \register_tick_function($function, $arg, $params);
if ($params !== []) {
$result = \register_tick_function($function, $arg, ...$params);
} elseif ($arg !== null) {
$result = \register_tick_function($function, $arg);
} else {
Expand Down
4 changes: 2 additions & 2 deletions generated/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ function session_regenerate_id(bool $delete_old_session = false): void
function session_register($name, ...$params): void
{
error_clear_last();
if ($params !== null) {
$result = \session_register($name, $params);
if ($params !== []) {
$result = \session_register($name, ...$params);
} else {
$result = \session_register($name);
}
Expand Down
4 changes: 2 additions & 2 deletions generated/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ function metaphone(string $str, int $phonemes = 0): string
function sprintf(string $format, $args = null, ...$params): string
{
error_clear_last();
if ($params !== null) {
$result = \sprintf($format, $args, $params);
if ($params !== []) {
$result = \sprintf($format, $args, ...$params);
} elseif ($args !== null) {
$result = \sprintf($format, $args);
} else {
Expand Down
14 changes: 11 additions & 3 deletions generator/src/WritePhpFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ private function writePhpFunction(): string
} else {
$phpFunction .= ' ';
}
$defaultValue = $lastParameter->getDefaultValue();
$defaultValueToString = ($defaultValue === null) ? 'null' : $defaultValue;
if ($lastParameter->isVariadic()) {
$defaultValueToString = '[]';
} else {
$defaultValue = $lastParameter->getDefaultValue();
$defaultValueToString = ($defaultValue === null) ? 'null' : $defaultValue;
}
$phpFunction .= 'if ($'.$lastParameter->getParameter().' !== '.$defaultValueToString.') {'."\n";
$phpFunction .= ' $result = '.$this->printFunctionCall($method)."\n";
$phpFunction .= ' }';
Expand Down Expand Up @@ -161,7 +165,11 @@ private function printFunctionCall(Method $function): string
{
$functionCall = '\\'.$function->getFunctionName().'(';
$functionCall .= implode(', ', \array_map(function (Parameter $parameter) {
return '$'.$parameter->getParameter();
$str = '';
if ($parameter->isVariadic()) {
$str = '...';
}
return $str.'$'.$parameter->getParameter();
}, $function->getFunctionParam()));
$functionCall .= ');';
return $functionCall;
Expand Down

0 comments on commit 60c6384

Please sign in to comment.