Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 5, 2021

@staabm
Copy link
Contributor Author

staabm commented Nov 5, 2021

the syntax errors seem unrelated as these also happen on the master branch. this is good to go - I think.

@staabm staabm changed the title implemented CallUserFuncDynamicReturnTypeExtension implemented call_user_func & call_user_func_array dynamic return type extensions Nov 5, 2021
@staabm
Copy link
Contributor Author

staabm commented Nov 9, 2021

@ondrejmirtes should be ready to merge

@staabm
Copy link
Contributor Author

staabm commented Nov 18, 2021

rebased against master. all green now.

Copy link
Contributor

@mglaman mglaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few thoughts, wondering if we could expand some of the testing and concerns of FuncCall when it's a StaticCall.

@staabm staabm changed the title implemented call_user_func & call_user_func_array dynamic return type extensions implemented call_user_func & call_user_func_array dynamic return type extensions Nov 19, 2021
Comment on lines 37 to 51
function proxy() {
$params = [
'CallUserFuncArray\generic',
[123]
];

assertType('int', call_user_func_array(...$params));

$params = [
'CallUserFuncArray\generic',
123,
456
];

// cufa expect max 2 args
assertType('*NEVER*', call_user_func_array(...$params));
assertType('int', call_user_func(...$params));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea yet on how to implement this cases, where only a unpack-array is passed, as I don't know how to split/what to pass into the FuncCall - which expects the name and args separated.

all other cases seem to pass right now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that in this variadic case I will let the extension just return the $defaultReturn

@staabm
Copy link
Contributor Author

staabm commented Dec 2, 2021

@ondrejmirtes any feedback on this PR?

@ondrejmirtes
Copy link
Member

@staabm My top priority right now is PHP 8.1 support (https://phpstan.org/blog/plan-to-support-php-8-1). The main action is now happening in https://github.com/ondrejmirtes/BetterReflection/tree/ng and https://github.com/phpstan/phpstan-src/tree/ng-better-reflection. Once this is finished and released, the operations will return to normal eventually. I now have 187 emails in my inbox worthy of my attention (all related to PHPStan), so please stay tuned.

@staabm
Copy link
Contributor Author

staabm commented Dec 2, 2021

@ondrejmirtes I see, thx for the update. if you see small issues I can fix to support you on the php 8.1 tasks, feel free to ping me

$callbackType = $scope->getType($args[0]->value);
$callbackArgsType = $scope->getType($args[1]->value);

if ($callbackType->isCallable()->yes() && $callbackArgsType->isArray()->yes()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this entire codeblock about? Why are there instanceof specific AST nodes like Array_ and Variable?

Copy link
Contributor Author

@staabm staabm Jan 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block is about unwrapping the passed in array-arg so that each array-item can be re-wrapped into Arg objects and passed thru to the FuncCall

call_user_func_array('CallUserFuncArray\fun3', [1 ,2 ,3]) -> CallUserFuncArray\fun3(1, 2, 3);

@ondrejmirtes
Copy link
Member

Hi, I'm cleaning up old and stale PRs. Please send a new PR if you're still interested, thanks.

This has been a draft for about a year.

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.

call_user_func_array return type based on callback-returntype
5 participants