Skip to content

Omitted = null optional arguments behave as non-null at runtime #348

@nahime0

Description

@nahime0

Summary

Omitted optional arguments with a default value of null are not materialized as null at runtime. Branches that test $arg !== null behave as if the argument were populated even when the caller omitted it.

Minimal repro

<?php
function f($v = null) {
    echo $v !== null ? 'x' : 'n';
}

f();

Steps to reproduce

  1. Save the file above as main.php.
  2. Run php main.php.
  3. Run cargo run -- main.php && ./main.

Expected behavior

PHP prints:

n

Actual behavior

Elephc prints:

x

A closure variant shows the same underlying bug:

<?php
$f = function($v = null) {
    echo $v !== null ? 'x' : 'n';
};
$f();

PHP prints n, Elephc prints x.

Notes

This looks like a call-lowering/runtime argument materialization bug rather than a closure-specific issue. The same mismatch appears in regular functions and closures.

Environment

  • elephc version: 0.23.7
  • Host OS: macOS / Darwin arm64
  • PHP reference: PHP 8.4.19 (cli)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcodegenCode generation (assembly emission)control-flowControl structures (if, loops, switch...)php-compatibilityPHP compatibility / deviation from PHP behaviorruntimeRuntime library / GC / ownership

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions