Opaque Objects & GdImage/CURLHandle
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);
}
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
23 Mar 2026
Views
21
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
Amazonbot 1
No pings yesterday
Amazonbot 9
Unknown AI 3
Perplexity 2
Google 2
ChatGPT 1
Ahrefs 1
Also referenced
How they use it
crawler 16
crawler_json 1
pre-tracking 1
Related categories
⚡
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