CKTIS / PHP
Tipo PHP resource
Una risorsa è un riferimento gestito da un’estensione PHP, ad esempio a un flusso aperto.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
is_resource($handle)Una risorsa è un riferimento gestito da un’estensione PHP, ad esempio a un flusso aperto. Verifica se fopen ha restituito false e chiudi il flusso con fclose. Dopo la chiusura is_resource restituisce false. resource non è disponibile come tipo nativo di parametro o di ritorno.
$handle = fopen('php://memory','w+');
if ($handle === false) { throw new RuntimeException('open'); }
$opened = is_resource($handle);
fwrite($handle,'R'); rewind($handle);
$text = stream_get_contents($handle); fclose($handle);
echo json_encode([$opened,$text,is_resource($handle)]);
[true,"R",false]
Esempi
<?php
$handle = fopen('php://memory','w+');
if ($handle === false) { throw new RuntimeException('open'); }
$opened = is_resource($handle);
fwrite($handle,'R'); rewind($handle);
$text = stream_get_contents($handle); fclose($handle);
echo json_encode([$opened,$text,is_resource($handle)]);
Risultato
[true,"R",false]