Skip to content

Reading an undeclared property of a class-typed object through ?? / isset returns the object's first field instead of null. #359

Closed

Description

@blacktrs

Summary

Reading an undeclared property of a class-typed object through ?? / isset returns the object's first field instead of null.

Repro

<?php
function viaThrowable(Throwable $t) { return $t->nope ?? 'dflt'; }
function viaClass(RuntimeException $t) { return $t->nope ?? 'dflt'; }
function viaIsset(Throwable $t) { return isset($t->nope); }
function viaNullsafe(?Throwable $t) { return $t?->nope ?? 'dflt'; }
interface I {}
class C implements I { public string $m = 'mm'; }
function viaIface(I $o) { return $o->nope ?? 'dflt'; }
function viaIssetIface(I $o) { return isset($o->nope) ? 'set' : 'unset'; }
try { throw new ValueError('x'); } catch (Throwable $e) { echo json_encode($e->errorInfo ?? null), "\n"; }
var_dump(viaThrowable(new RuntimeException('z')));
var_dump(viaClass(new RuntimeException('z')));
var_dump(viaIsset(new RuntimeException('z')));
var_dump(viaNullsafe(new LogicException('z')));
var_dump(viaNullsafe(null));
var_dump(viaIface(new C));
var_dump(viaIssetIface(new C));
$s = new stdClass; $s->nope = 'dyn';
function viaObj(object $o) { return $o->nope ?? 'dflt'; }
var_dump(viaObj($s), viaObj(new C));

Expected (php)

null
string(4) "dflt"
string(4) "dflt"
bool(false)
string(4) "dflt"
string(4) "dflt"
string(4) "dflt"
string(5) "unset"
string(3) "dyn"
string(4) "dflt"

Actual (manticore f8cc6547, Darwin arm64)

4337177888
string(1) "z"
string(1) "z"
bool(true)
int(4337177928)
string(4) "dflt"
string(2) "mm"
string(3) "set"
string(3) "dyn"
string(4) "dflt"

Tracking

Known-bug repro: tests/aot/repro/wrong/undefined_prop_on_class_typed_reads_first_field.php — bash tests/aot/xfail.sh -k undefined_prop_on_class_typed_reads_first_field 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 19, 2026
  2. added 3 commits that reference this issue on Oct 19, 2026
    2d37b11
    df55e07
    7b8ad6b
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