Skip to content

Why call_user_func_array ? #51

@dakujem

Description

@dakujem

Why use call_user_func_array when it's slower than native function invoking, or even call_user_func?

$callable = fn() => null;
$args = [];

call_user_func_array($callable, $args); //  slowest
call_user_func($callable, ...$args); //     faster
$callable(...$args); //                     fastest

I believe those are all equivalent options, across PHP versions 5, 7 and 8.
It has been optimized in the PHP core since the dark ages, but still the native call should be the fastest one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions