We just upgraded our application to PHP7 with Phalcon 3.0.3. Before this upgrade, we were working with PHP 5.6 and Phalcon 2.0.13.
Without event touching anything, we discovered that one of our Tasks is not working anymore.
To access our CLI module, we perform this call:
php cron.php name_of_task name_of_action arg1 arg2
In order to deduce the name of the Task and the name of the Action to call from the arguments passed, we implemented this method in cron.php
:
private function parseArguments() {
global $argv, $argc;
$parameters = array();
$dispatcher = $this->getDI()->get('dispatcher');
if( isset( $argv ) and ( $argc > 0 ) ) {
foreach( $argv as $k => $arg ) {
if( $k == 1 ) {
$dispatcher->setTaskName( $arg );
} elseif( $k == 2 ) {
$dispatcher->setActionName( $arg );
} elseif( $k >= 3 ) {
$parameters[] = $arg;
}
}
}
$dispatcher->setParams( $parameters );
}
Everything works fine (just like before the upgrade) excepts for those Actions that require one or more arguments.
For example, if we call:
php cron.php test test 1
The Dispatcher instantiates TestTask
and invokes testAction( $argument )
.
However, if the first instruction of TestTask::testAction()
is:
var_dump( $argument );
exit;
The printed result is:
array(1) {
[0]=>
string(1) "1"
}
instead of just:
string(1) "1"
Why?