CKTIS / PHP
Tipo do PHP resource
Um recurso é uma referência gerida por uma extensão do PHP, como a que identifica um fluxo aberto.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
is_resource($handle)Um recurso é uma referência gerida por uma extensão do PHP, como a que identifica um fluxo aberto. Verifique se fopen devolveu false e feche o fluxo com fclose. Depois de o fechar, is_resource devolve false. O PHP não aceita resource como tipo nativo de parâmetro ou de retorno.
$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]
Exemplos
<?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)]);
Resultado
[true,"R",false]