CKTIS / PHP
PHP-Typ resource
Eine Ressource ist ein von einer PHP-Erweiterung verwaltetes Handle, etwa für einen offenen Stream.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
is_resource($handle)Eine Ressource ist ein von einer PHP-Erweiterung verwaltetes Handle, etwa für einen offenen Stream. Prüfe das Ergebnis von fopen auf false und schließe den Stream mit fclose. Anschließend liefert is_resource für das Handle false. resource ist als nativer Parameter- oder Rückgabetyp nicht verfügbar.
$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]
Beispiele
<?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)]);
Ergebnis
[true,"R",false]