Skip to content

== of a property array against its array_map copy is false once a second new passes a differently shaped literal to the same constructor #154

Closed

Description

@blacktrs

Summary

Comparing an object's array property with an array_map copy of itself returns false where php returns true. It only happens when the same constructor is called a second time, later in the program, with an array literal of a different shape. Without the second new, the comparison is correct.

Impact

A wrong boolean with no warning or crash. Any code that compares collections held in a typed array property can take the wrong branch depending on unrelated new calls elsewhere in the file. The result depends on whole-program shape, not on the comparison itself, so it is hard to diagnose.

Repro

<?php
class T { public array $rows; function __construct(array $r) { $this->rows = $r; } }
$t = new T([['a' => null]]);
var_dump($t->rows == array_map(fn($x) => $x, $t->rows));
$k = new T([[1]]);

Expected (php)

bool(true)

Actual

bool(false)

Notes

  • Removing the last line makes the output correct, so the comparison is being compiled against a property type that has been widened by the second call site.
  • Reproduces on the v0.13.0 bootstrap compiler and on the current tip of dsmap, so it is not caused by the Ds work in progress.
  • Found while fixing the alpine failure of array_eq_nested_lists_null_rows, which is unrelated: that one was a use-after-free in literal arguments.

Tracking

Known-bug repro: tests/aot/repro/wrong/array_eq_rows_after_second_ctor_literal.php. bash tests/aot/xfail.sh -k array_eq_rows_after_second_ctor_literal reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

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