Skip to content

A false returned by a false|Box function and passed to a Box-typed parameter raises no TypeError (the callee reads null). #484

Closed

Description

@blacktrs

Summary

A false returned by a false|Box function and passed to a Box-typed parameter raises no TypeError (the callee reads null).

Repro

<?php
class Box { public int $n = 1; }
function make(bool $ok): false|Box { return $ok ? new Box() : false; }
function use_box(Box $b): int { return $b->n; }
try {
    echo use_box(make(false)), "\n";
} catch (TypeError $e) {
    echo get_class($e), ': ', explode(', called in', $e->getMessage())[0], "\n";
}
echo use_box(make(true)), "\n";

Expected (php)

TypeError: use_box(): Argument #1 ($b) must be of type Box, false given
1

Actual (manticore 71979b71, Darwin arm64)


[exit code 255]
PHP Fatal error:  Uncaught Error: Attempt to read property "n" on null

Tracking

Known-bug repro: tests/aot/repro/wrong/false_into_object_param_no_typeerror.php — bash tests/aot/xfail.sh -k false_into_object_param_no_typeerror 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
  2. blacktrs commented on Oct 25, 2026

    @blacktrs
    ContributorAuthor

    Same root, method-call receiver: make(false)->get() (make(): false|Box) — php throws Error: Call to a member function get() on false; natively it SIGSEGVs in a minimal program, and inside the mysqli prelude it reads Call to a member function __mcRs() on null (e.g. $stmt->get_result()->fetch_all() when get_result() returns false, or $m->prepare(...)->bind_param() after a failed prepare). Case appended to tests/aot/repro/wrong/false_into_object_param_no_typeerror.php.

  3. blacktrs commented on Oct 26, 2026

    @blacktrs
    ContributorAuthor

    The issue is addressed partially. Hence, reopening

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