Example 1 — Checking a File Handle
Open an in-memory stream with fopen() and compare it with a string and null.
<?php
$handle = fopen('php://memory', 'r+');
var_dump(is_resource($handle));
var_dump(is_resource('php://memory'));
var_dump(is_resource(null));
fclose($handle); How It Works
- fopen() opens a stream. The php://memory stream lives in memory, so no real file is needed.
- The handle is an open resource. is_resource() returns true for it.
- The string and null are not resources. They return false even though the string names a stream.
- fclose() frees the handle. It is good practice to close every handle you open.

