Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Convert call_user_func where appropriate to native calls #29932

Merged
merged 1 commit into from
Sep 10, 2019

Conversation

GrahamCampbell
Copy link
Member

Note that it is not always possible or sensible to convert every instance of call_user_func, so I haven't - I have changed the ones where it is safe to do so, and doesn't make the syntax worse. The advantage to avoiding call_user_func is a performance speed up, and easy reading.

Be careful if someone else sends a follow PR converting the rest, because the implementation will likely be incorrect. For example, in the eloquent query builder, changing the call_user_funcs on the $querys will actually change the order of execution and be incorrect!

@GrahamCampbell
Copy link
Member Author

GrahamCampbell commented Sep 10, 2019

Similarly, one should be careful not to accept blind call_user_func_array conversions, since the behaviour will be different with associative arrays...

@taylorotwell taylorotwell merged commit f5c5699 into 6.x Sep 10, 2019
@driesvints driesvints deleted the callable branch September 10, 2019 15:19
$stateAttributes,
$this->faker, $attributes
);
return $stateAttributes($this->faker, $attributes);
Copy link
Member

@crynobone crynobone Sep 11, 2019

Choose a reason for hiding this comment

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

Here it's checking for is_callable(), if you give [$object, 'bar'] it going to return true, but AFAIK it not possible to do [$object, 'bar'](...)

Tested, seem to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeh, you can call callables like that. The two cases I didn't convert are ones with assignments to the variable holding the callable within the call_user_func parameters, and callables which were properties of classes.

voku added a commit to voku/framework that referenced this pull request Mar 2, 2020
- fix phpdocs
- add static (for anonymous functions, less for for PHP and for the IDE, because $this is not allowed)
- use some more modern phpdocs (e.g. array => Model[])
- use php7 features like "array-unpacking"
- replace "call_user_func" (laravel#29932 <- the test did not fail, but maybe I missed something here)
- use "array_values()" only if needed
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