Baza znanjaCentar za ispite
HRHrvatski
Odaberi jezik13

CKTIS / PHP

Moduli i granice

Datoteka PHP može biti modul koji vraća pozivljivu vrijednost ili postavke. require je izvršava i daje rezultat.

Verzija: PHP 8.4; repository runtime, production runtime not attested

Sintaksa

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

Datoteka PHP može biti modul koji vraća pozivljivu vrijednost ili postavke. require je izvršava i daje rezultat. Uključeni kod nasljeđuje doseg varijabli mjesta uključivanja, stoga ovisnosti predajte kao argumente izvezenoj funkciji. Kasniji require_once vraća 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]

Primjeri

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

Izvori