Skip to content

Assigning a non-numeric string to a typed int property is accepted silently instead of throwing TypeError "Cannot assign string to property Tp::$x of type int" #466

Closed

Description

@blacktrs

Summary

Assigning a non-numeric string to a typed int property is accepted silently instead of throwing TypeError "Cannot assign string to property Tp::$x of type int".

Repro

<?php
class Tp { public int $x = 0; }
$o = new Tp();
try { $o->x = 'abc'; echo "no error\n"; } catch (Throwable $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; }
$k = 'x';
try { $o->$k = 'abc'; echo "no error\n"; } catch (Throwable $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; }

Expected (php)

TypeError: Cannot assign string to property Tp::$x of type int
TypeError: Cannot assign string to property Tp::$x of type int

Actual (manticore d419d722, Darwin arm64)

no error
no error

Tracking

Known-bug repro: tests/aot/repro/wrong/typed_int_property_accepts_non_numeric_string.php — bash tests/aot/xfail.sh -k typed_int_property_accepts_non_numeric_string reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions