Baza znanjaIzpitno središče
SLSlovenščina
Izberi jezik13

CKTIS / PHP

Moduli in njihove meje

Datoteka PHP lahko služi kot modul, ki vrne klicljivo vrednost ali nastavitve. require jo izvede in poda rezultat.

Različica: PHP 8.4; repository runtime, production runtime not attested

Sintaksa

return static fn(int $value): int => $value + 1;

Datoteka PHP lahko služi kot modul, ki vrne klicljivo vrednost ali nastavitve. require jo izvede in poda rezultat. Vključena koda podeduje območje spremenljivk mesta vključitve, zato odvisnosti podajte kot argumente izvoženi funkciji. Poznejši require_once vrne 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]

Primeri

<?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]);

Rezultat

[36,true]

Viri