Skip to content

Language: (array) object cast — TYPE_CAST_ARRAY VM opcode (#3328) - #3346

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-3328-cast-array-object
May 30, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-3328-cast-array-object

Conversation

@PurHur

@PurHur PurHur commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implements OpCode::TYPE_CAST_ARRAY in the VM via lib/VM/CastSupport.php so (array) on objects exports instance property values and on arrays performs a keyed copy (HashTable::replaceCopy()).
  • Adds compliance PHPT test/compliance/cases/language/cast_array_object.phpt (public properties + array copy isolation).

Lane note: Lane C (issue % 3 == 2) had no unclaimed implementation-ready language issues without an open PR; this picks the lowest unclaimed language parity gap (#3328).

php-src reference

  • Zend/zend_operators.c — cast_object, array cast / convert_to_array
  • Zend/zend_types.h — IS_ARRAY from object

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter cast_array_object test/compliance/VMTest.php'

Limits (follow-up)

  • JIT/AOT: TYPE_CAST_ARRAY still throws Unknown JIT opcode if compiled natively (VM path only for now).
  • Protected/private property key mangling (\0Class\0name) not implemented; public + raw storage names only.

Closes #3328

Made with Cursor

Add CastSupport::toArray() and wire OpCode::TYPE_CAST_ARRAY in the VM
so (array) on objects exports instance properties and on arrays copies
keys via HashTable::replaceCopy(). Matches Zend for public props and
array copy semantics; protected/private mangling is follow-up.

php-src: Zend/zend_operators.c (cast_object), convert_to_array
Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit dd5db5a into master May 30, 2026
@PurHur
PurHur deleted the agent/issue-3328-cast-array-object branch May 30, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: (array) object cast — TYPE_CAST_ARRAY VM opcode (Zend cast_object parity)

1 participant