CKTIS / PHP
Ingangspunt van het programma
CLI voert de instructies op bestandsniveau van het gekozen script uit.
Versie: PHP 8.4; repository runtime, production runtime not attested
Syntax
php script.php [argument ...]CLI voert de instructies op bestandsniveau van het gekozen script uit. Een eigen main loopt alleen bij aanroep. Als argv aanstaat identificeert $argv[0] het script en volgen de argumenten. Een argumentenarray doorgeven maakt standaardwaarden afzonderlijk testbaar.
function main(array $args):string{return $args[1]??"default";}
if (isset($argv[1])) {echo main($argv);exit;}
echo json_encode([PHP_SAPI,is_file($argv[0]),main($argv)]),"\n";
$run=proc_open([PHP_BINARY,$argv[0],"short"],[1=>["pipe","w"]],$pipes);echo stream_get_contents($pipes[1]);fclose($pipes[1]);proc_close($run);
["cli",true,"default"]
short
Voorbeelden
<?php
function main(array $args):string{return $args[1]??"default";}
if (isset($argv[1])) {echo main($argv);exit;}
echo json_encode([PHP_SAPI,is_file($argv[0]),main($argv)]),"\n";
$run=proc_open([PHP_BINARY,$argv[0],"short"],[1=>["pipe","w"]],$pipes);echo stream_get_contents($pipes[1]);fclose($pipes[1]);proc_close($run);
Resultaat
["cli",true,"default"] short