Skip to content

Language: null default on non-nullable typed property fatal message — Zend suggests ?T (zend_compile.c) #31820

Description

@PurHur

Category

Language: · php-src-strict · compile-time typed property default

Problem

public int $x = null; (and other non-nullable typed properties defaulting to null) must be a compile fatal. Zend’s message tells the user to use the nullable form; the compiler’s parseAndCompile failure uses a shorter, different string.

Probed 2026-08-17 — host Zend PHP 8.2 vs php bin/vm.php.

Repro Zend 8.2+ VM / compile (2026-08-17)
class T { public int $x = null; } Fatal error: Default value for property of type int may not be null. Use the nullable type ?int to allow null default value parseAndCompile failure: … Cannot use null as default value for property $x of type int
class T {
    public int $x = null;
}

php-src reference

PHP implementation target

  • lib/Compiler.php / property default type check — emit Zend’s fatal wording (include “Use the nullable type ?T …”)
  • Prefer matching Zend’s E_COMPILE_ERROR / Fatal presentation used elsewhere for compile fatals
  • php-in-PHP — no new C runtime branch

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_null_default_typed_prop.php' ; true
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_null_default_typed_prop.php' ; true

Done when

  • Compile fatal message matches Zend for public T $prop = null on non-nullable T (at least int / string / float / bool / class types)
  • Nullable ?int $x = null still accepted
  • Compliance / compile-error .phpt guard under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 17, 2026
  2. PurHur commented on Aug 17, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler Worker Lane B — starting this run (lane overflow: no eligible IR in lane B; stdlib/ext-owned queue skipped)

  3. PurHur commented on Aug 17, 2026

    @PurHur
    OwnerAuthor

    claim: Worker lane B — starting this run (lane overflow: no eligible IR in lane B; stdlib/ext-owned queue + named ext soap/imagick/sqlsrv skipped)

  4. PurHur commented on Aug 17, 2026

    @PurHur
    OwnerAuthor

    Merged #31827

    Verification

    • php bin/vm.php test/repro/maintainer_gap_null_default_typed_prop.php → Zend wording + exit 255
    • ./script/phpunit.sh --filter TypedPropNullDefaultFatal31820 → OK (4 tests, 6 assertions) VM+JIT
  5. PurHur commented on Aug 17, 2026

    @PurHur
    OwnerAuthor

    Follow-up merged: #31829

    #31827 landed the Zend message text; #31829 upgrades presentation to CompileFatal / PHP Fatal error: (file+line) so the CLI matches Zend’s fatal shape instead of parseAndCompile failure:.

    Verification: php bin/vm.php test/repro/maintainer_gap_null_default_typed_prop.php → exit 255, PHP Fatal error: … Use the nullable type ?int …; ./script/phpunit.sh --filter TypedPropNullDefaultFatal31820 → OK (4).

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

    area:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions