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

Opaque Objects & GdImage/CURLHandle

PHP PHP 8.0+ Intermediate
debt(d3/e1/b2/t6)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3), PHPStan and Rector (listed in detection_hints) readily flag is_resource() calls on GdImage/CurlHandle and missing type hints — this is a well-known migration pattern.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1), quick_fix is literally replacing is_resource() with instanceof GdImage/CurlHandle — a mechanical one-line swap Rector can automate.

b2 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3) but lighter, scoring b2 — the choice only affects functions interacting with GD/cURL/XML extensions, not the broader codebase shape; it's a localised concern at extension boundaries.

t6 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7) leaning down to t6 — the misconception is that these behave like resources (legacy PHP 7) or like regular objects, but is_resource() silently returns false in PHP 8+, contradicting decades of PHP resource idioms; clone/serialize also unexpectedly fail.

About DEBT scoring →

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 39
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 3 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 ChatGPT 3 Unknown AI 3 Perplexity 3 Ahrefs 3 Google 2 Claude 2 Bing 2 SEMrush 2 Scrapy 2 Meta AI 1
crawler 28 crawler_json 4 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