Skip to content

Remove assert() on CallLike::getArgs(), returns empty array on first class callable#1138

Open
samsonasik wants to merge 1 commit intonikic:masterfrom
samsonasik:remove-assert-get-args
Open

Remove assert() on CallLike::getArgs(), returns empty array on first class callable#1138
samsonasik wants to merge 1 commit intonikic:masterfrom
samsonasik:remove-assert-get-args

Conversation

@samsonasik
Copy link
Contributor

In tools like Rector and PHPStan, we use getArgs() a lot, which it will trigger assert error:

There was 1 failure:

1) Rector\Tests\Php73\Rector\FuncCall\SetcookieRector\SetCookieRectorTest::test#1 with data ('/Users/samsonasik/www/rector-...hp.inc')
assert(!$this->isFirstClassCallable())

/Users/samsonasik/www/rector-src/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php:32

when enabling:

ini-values: zend.assertions=1

I think to avoid repetitive check:

        if ($node->isFirstClassCallable()) {
              return null;
        }

       $args = $node->getArgs();

We can carefully check that, but sometime, we forgot.

I think the returns can be early return empty array when it is first class callable.

User that want to get both Arg and VariadicPlaceholder can use ->args public property instead.

/cc @TomasVotruba @ondrejmirtes @ruudk @staabm

@samsonasik
Copy link
Contributor Author

Ready for review 👍

@TomasVotruba
Copy link
Contributor

This would be great improvement 👍 as the expectation would be code-dependent, not server-dependent.

@ondrejmirtes
Copy link
Contributor

I disagree, this would be a BC break and a source of hard-to-find bugs.

@ondrejmirtes
Copy link
Contributor

Also, we need to think about the design of Partial Function Application calls in the AST for PHP 8.6.

@samsonasik
Copy link
Contributor Author

samsonasik commented Jan 28, 2026

@ondrejmirtes the signature doesn't change, it returns @return Arg[], if assert is used, and assert php.ini is disabled, previously can returns both Arg[] and VariadicPlaceholder[]:

ini_set('zend.assertions', '0');

assert(true === false);
echo "here executed";

which tool may can't control as can happen on php.ini and may be used for Arg only.

This make consistent, all Arg, or empty.

I am open for optional parameter flag, but that seems will be error incompatible param on child of ClassLike on custom Node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants