← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Opaque Objects & GdImage/CURLHandle

php PHP 8.0+ Intermediate

TL;DR

PHP 8.0 replaced resource types (gd, curl, xml) with opaque objects — GdImage, CurlHandle, XMLParser — improving type safety and OOP integration.

Explanation

Before PHP 8.0, many extensions returned resource types (is_resource() check, no type hints). PHP 8.0+ returns typed objects: imagecreatetruecolor() returns GdImage, curl_init() returns CurlHandle, xml_parser_create() returns XMLParser. These are opaque — you can't inspect their internals — but they're proper objects with type hints and are accepted by instanceof. Old code using is_resource() checks breaks. Type hints now possible: function process(GdImage $image). These objects are still reference-counted and freed when no longer referenced, similar to resources.

Common Misconception

Opaque objects like GdImage behave like regular PHP objects — they're opaque wrappers with no accessible properties, just type safety.

Why It Matters

Typed opaque objects enable type hints for extension functions, eliminating the need for is_resource() checks and enabling IDE/static analysis support.

Common Mistakes

  • Using is_resource() on GdImage/CurlHandle in PHP 8.0+ — always returns false.
  • Not type-hinting function parameters accepting GdImage/CurlHandle.
  • Trying to clone or serialize opaque objects — not supported.

Code Examples

✗ Vulnerable
$image = imagecreatetruecolor(100, 100);
if (!is_resource($image)) { // Always false in PHP 8!
    throw new Exception('Failed to create image');
}
✓ Fixed
$image = imagecreatetruecolor(100, 100);
if (!($image instanceof \GdImage)) {
    throw new \RuntimeException('Failed to create image');
}

function applyFilter(\GdImage $img, int $filter): void {
    imagefilter($img, $filter);
}

Added 23 Mar 2026
Views 21
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
Amazonbot 1
No pings yesterday
Amazonbot 9 Unknown AI 3 Perplexity 2 Google 2 ChatGPT 1 Ahrefs 1
crawler 16 crawler_json 1 pre-tracking 1
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Replace is_resource() checks with instanceof GdImage / CurlHandle / XMLParser. Add type hints to functions accepting these objects.
📦 Applies To
PHP 8.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
is_resource\(
Auto-detectable: ✓ Yes rector phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Line

✓ schema.org compliant