php-cron-scheduler icon indicating copy to clipboard operation
php-cron-scheduler copied to clipboard

Unexpected argument passed into Job->call()'s Closure

Open veloper opened this issue 6 years ago • 2 comments

Environment

  • PHP 5.6
  • composer require peppeocchi/php-cron-scheduler:^2.3

How to Reproduce

$scheduler = new \GO\Scheduler()

$scheduler->call( 
  function($args) {
    echo $args["foo"]; 
  }, 
  ["foo" => "bar"], 
  "ident"
)->everyMinute();

$scheduler->run();

Expected Behavior

Within the closure, and based on the docs, I expect $args to be an array and for $args["foo"] to equal "bar".

Observed Behavior

However, that actual value of $args is a string that equals "bar".

Possible Solutions

  • Change the docs
  • Change call_user_func_array($fn, $args) to call_user_func($fn, $args)
    • https://github.com/peppeocchi/php-cron-scheduler/blob/master/src/GO/Job.php#L431

veloper avatar Apr 20 '18 16:04 veloper

Hi @veloper thanks for pointing that out, I think the safest approach is just to update the docs what do you think? If the second solution is not causing any breaking change I'd be happy to go for n.2

Do you want to create a PR with your solution?

peppeocchi avatar May 14 '18 09:05 peppeocchi

@peppeocchi - I'd go with the safest approach as well; update the docs. Normally I'd make a PR but I'm under a deadline right now.

veloper avatar May 14 '18 13:05 veloper