Skip to content

Reading a typed property that was never initialised answers the zero of its type instead of throwing #417

Closed

Description

@blacktrs

Summary

Reading a typed property that was never initialised answers the zero of its type instead of throwing.

Repro

<?php
class A { public int $x; public string $s; }
$a = new A;
try { var_dump($a->x); } catch (Error $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; }
try { var_dump($a->s); } catch (Error $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; }

Expected (php)

Error: Typed property A::$x must not be accessed before initialization
Error: Typed property A::$s must not be accessed before initialization

Actual (manticore 35461ba2, Darwin arm64)

int(0)
NULL

Tracking

Known-bug repro: tests/aot/repro/wrong/typed_property_read_before_init_returns_zero.php — bash tests/aot/xfail.sh -k typed_property_read_before_init_returns_zero 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 24, 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