Skip to content

Commit

Permalink
Callback::invoke() and invokeArgs() are deprecated in favor of native…
Browse files Browse the repository at this point in the history
… invocation
  • Loading branch information
dg committed Feb 16, 2018
1 parent fd87fe8 commit c0ab1b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Utils/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function closure($callable, string $method = null): \Closure
*/
public static function invoke($callable, ...$args)
{
trigger_error(__METHOD__ . '() is deprecated, une native invoking.', E_USER_DEPRECATED);
self::check($callable);
return $callable(...$args);
}
Expand All @@ -53,6 +54,7 @@ public static function invoke($callable, ...$args)
*/
public static function invokeArgs($callable, array $args = [])
{
trigger_error(__METHOD__ . '() is deprecated, une native invoking.', E_USER_DEPRECATED);
self::check($callable);
return $callable(...$args);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Utils/Callback.invoke.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ class Test


$cb = [new Test, 'fun'];
Assert::same('Test::fun*', Callback::invoke($cb, '*'));
Assert::same('Test::fun*', Callback::invokeArgs($cb, ['*']));
Assert::same('Test::fun*', @Callback::invoke($cb, '*')); // is deprecated
Assert::same('Test::fun*', @Callback::invokeArgs($cb, ['*'])); // is deprecated


$cb = [new Test, 'ref'];
Assert::same('Test::ref', Callback::invokeArgs($cb, [&$ref]));
Assert::same('Test::ref', @Callback::invokeArgs($cb, [&$ref])); // is deprecated
Assert::same('Test::ref', $ref);


Assert::exception(function () {
Callback::invoke('undefined');
@Callback::invoke('undefined'); // is deprecated
}, Nette\InvalidArgumentException::class, "Callback 'undefined' is not callable.");


Assert::exception(function () {
Callback::invokeArgs('undefined');
@Callback::invokeArgs('undefined'); // is deprecated
}, Nette\InvalidArgumentException::class, "Callback 'undefined' is not callable.");

0 comments on commit c0ab1b9

Please sign in to comment.