php8.5
Home/ Manual/ yaf / yaf_application/ Yaf_Application::execute

Yaf_Application::execute

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Execute a callback

Description

Yaf_Application::execute(callable $callback, mixed ...$args): mixed

Execute a callback. This method is typically used to run Yaf in a cron job or other CLI script, so that the script can reuse the autoloader and the bootstrap mechanism.

Parameters

callback

A valid callback to execute.

args

Optional parameters passed to the callback.

Return Values

Returns whatever the callback returns, or false if calling the callback failed.

Examples

Yaf_Application::execute() example

php
<?php
function main($argc, $argv) {
    var_dump($argc);
    var_dump($argv);
}

$config = array(
    "application" => array(
        "directory" => realpath(dirname(__FILE__)) . "/application",
    ),
);

/** Yaf_Application */
$application = new Yaf_Application($config);
$application->execute("main", $argc, $argv);
?>

The above example will output something similar to:

output
int(2)
array(2) {
  [0]=>
  string(11) "execute.php"
  [1]=>
  string(3) "arg"
}

See Also

  • Yaf_Application::bootstrap

Source: reference/yaf/yaf_application/execute.xml · from the official PHP manual (php/doc-en)