CKTIS / PHP
Moduly a jejich hranice
Soubor PHP může být modulem vracejícím callable nebo konfiguraci. require jej vyhodnotí a získá výsledek.
Verze: PHP 8.4; repository runtime, production runtime not attested
Syntaxe
return static fn(int $value): int => $value + 1;Soubor PHP může být modulem vracejícím callable nebo konfiguraci. require jej vyhodnotí a získá výsledek. Vložený kód dědí rozsah proměnných místa vložení, proto závislosti předávejte exportované funkci argumenty. Pozdější require_once vrátí true.
$file=tempnam(sys_get_temp_dir(),"module");file_put_contents($file,'<?php return static fn(int $cents,int $qty):int=>$cents*$qty;');$price=require $file;$again=require_once $file;unlink($file);echo json_encode([$price(12,3),$again]);
[36,true]
Příklady
<?php
$file=tempnam(sys_get_temp_dir(),"module");file_put_contents($file,'<?php return static fn(int $cents,int $qty):int=>$cents*$qty;');$price=require $file;$again=require_once $file;unlink($file);echo json_encode([$price(12,3),$again]);
Výsledek
[36,true]