Skip to content

Language: typed property write enforcement on VM (#169) - #3828

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-169-typed-properties
May 30, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-169-typed-properties

Conversation

@PurHur

@PurHur PurHur commented May 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • Enforce typed property writes on VM: reject invalid assignments (e.g. arraystring, arrayint|string) with Zend-style TypeError messages matching zend_verify_property_type / zend_type.c.
  • Persist union type metadata on property prototypes (unionTypeConstraints, declaredTypeLabel) and handle scalar weak coercion without array/object → string conversion.
  • Fix instance readonly property enforcement: php-cfg previously stripped MODIFIER_READONLY from property visibility; new php-cfg-property-readonly.patch preserves the flag (promoted readonly already worked via promotionReadonly).

php-src reference

  • Zend/zend_execute.cZEND_ASSIGN_OBJ, typed property checks
  • Zend/zend_type.c — union assignability
  • Zend/zend_object_handlers.c — readonly property guard

Verification

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

Repro (VM now matches Zend):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "
class C { public string \$x = \"\"; \$c = new C(); try { \$c->x = []; } catch (Throwable \$e) { echo \$e->getMessage(); }
"'
# Cannot assign array to property C::$x of type string

Closes #169

Made with Cursor

Persist union/readonly property metadata from the compiler, reject invalid
assignments (array→scalar, union mismatch) with Zend-style TypeError messages,
and restore instance readonly enforcement via a php-cfg property-readonly patch.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur force-pushed the agent/issue-169-typed-properties branch from c2e1501 to b60925c Compare May 30, 2026 15:23
@PurHur
PurHur merged commit 6c423df into master May 30, 2026
@PurHur
PurHur deleted the agent/issue-169-typed-properties branch May 30, 2026 15:23
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: Typed properties, union types, and readonly (PHP 8+)

1 participant