Skip to content

Language: first-class callable on (new Class())->method(...) — TypeReconstructor compile crash #6725

Closed

Description

@PurHur

Category

language · php-src-strict

Problem

First-class callable syntax on a temporary instance (new Box())->add(...) must compile and run like Zend. #4957 / #6024 fixed $obj->method(...) on a named variable, but the inline new receiver still crashes during type reconstruction.

Runtime (new Box())->add(...) then $f(1,2)
Zend PHP 8.2+ prints 3
bin/vm.php Uncaught TypeError in PHPTypes\TypeReconstructor.php:303 (exit 255)

php-src reference

Repro (failure today)

test/repro-maintainer/repro_fcc_instance_compile.php:

<?php
declare(strict_types=1);

class Box {
    public function add(int $a, int $b): int {
        return $a + $b;
    }
}

$f = (new Box())->add(...);
echo $f(1, 2), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro-maintainer/repro_fcc_instance_compile.php 2>&1 | head -10
php test/repro-maintainer/repro_fcc_instance_compile.php'

Scope (this repo)

Layer Files
php-types vendor/ircmaxell/php-types — TypeReconstructor patch for Expr_FirstClassCallable whose var is Expr_New
Compiler lib/Compiler.php — lowering for bound callable from ephemeral object (ensure object lifetime through closure)
VM/JIT Reuse instance-method FCC path (#4040); JIT execute probe
Tests test/compliance/cases/language/fcc_new_instance.phpt

PHP-in-PHP: implement in lib/ + php-types overlay; no new C runtime.

Done when

  • VM/JIT/AOT: repro prints 3
  • Named-variable FCC ($b = new Box(); $f = $b->add(...)) still green
  • ./script/ci-fast.sh --filter fcc_new_instance green

Activity

  1. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  2. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    Merged via #6729.

    The compile crash was already fixed on master (#4957 — TypeReconstructor Expr_FirstClassCallable returns new Type(Type::TYPE_ARRAY) for method kind; compileFirstClassCallable lowers instance FCC via TYPE_INIT_ARRAY + TYPE_FROM_CALLABLE).

    This PR adds the missing compliance guard:

    • test/compliance/cases/language/fcc_new_instance.phpt
    • test/fixtures/aot/cases/fcc_new_instance.phpt

    Verification:

    php bin/vm.php test/repro-maintainer/repro_fcc_instance_compile.php  → 3
    vendor/bin/phpunit test/compliance/VMTest.php --filter fcc_new_instance  → OK
    vendor/bin/phpunit test/compliance/JITTest.php --filter fcc_new_instance  → OK
    vendor/bin/phpunit test/unit/FirstClassCallableTest.php --filter testVmInstanceMethodFirstClassCallable  → OK (3 tests)
    
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions