Skip to content

Zend: Make instanceof object equivalent to is_object()#22375

Open
dseguy wants to merge 1 commit into
php:masterfrom
dseguy:instance-object
Open

Zend: Make instanceof object equivalent to is_object()#22375
dseguy wants to merge 1 commit into
php:masterfrom
dseguy:instance-object

Conversation

@dseguy

@dseguy dseguy commented Jun 21, 2026

Copy link
Copy Markdown

$x instanceof object was syntactically valid but always returned false because object is a pseudo-type with no corresponding class entry in the class table. This made the construct silently unusable.

At compile time, when the right-hand side of instanceof is the literal object pseudo-type, emit ZEND_TYPE_CHECK with MAY_BE_OBJECT instead of ZEND_INSTANCEOF. This is the same opcode used by is_object(), so $x instanceof object now behaves identically to is_object($x).

The fix is entirely at compile time; no VM handler changes are required.

`$x instanceof object` was syntactically valid but always returned false
because `object` is a pseudo-type with no corresponding class entry in the
class table. This made the construct silently unusable.

At compile time, when the right-hand side of `instanceof` is the literal
`object` pseudo-type, emit `ZEND_TYPE_CHECK` with `MAY_BE_OBJECT` instead
of `ZEND_INSTANCEOF`. This is the same opcode used by `is_object()`, so
`$x instanceof object` now behaves identically to `is_object($x)`.

The fix is entirely at compile time; no VM handler changes are required.

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants