CKTIS / PHP
Modules and boundaries
A PHP file can act as a module by returning an explicit callable or configuration value. require evaluates that file and yields its returned value.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
return static fn(int $value): int => $value + 1;A PHP file can act as a module by returning an explicit callable or configuration value. require evaluates that file and yields its returned value. Included code inherits variables in the inclusion scope, so pass dependencies as arguments to the exported callable. Repeated require_once yields true after the initial load.
$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]
Examples
<?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]);
Result
[36,true]