Skip to content

align small PHP compatibility behaviors - #85

Merged
nvms merged 1 commit into
nvms:mainfrom
vapebw:fix/php-compat-small-fixes
Sep 21, 2026
Merged

nvms merged 1 commit into
nvms:mainfrom
vapebw:fix/php-compat-small-fixes

Conversation

@vapebw

@vapebw vapebw commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

In php 8.x, several standard library behaviors differ from zphp in small but observable compatibility cases:

  • array_rand($array, 1) returns a scalar key, just like omitting the second argument
  • array_diff() / array_intersect() and their key/assoc variants accept a single array and return it unchanged
  • date_get_last_errors() is available as the procedural alias of DateTime::getLastErrors()

Previously:

  • array_rand($array, 1) returned a one-element array instead of a scalar key
  • single-array diff/intersect calls returned null
  • date_get_last_errors() was not registered even though the underlying implementation already existed

Solution

  • Return the scalar-key path whenever array_rand() receives num == 1
  • Allow arraySetOp() to operate with a single array, reusing the existing empty comparison logic
  • Register date_get_last_errors() using the existing dtGetLastErrors implementation

Tests

  • Added coverage for array_rand() with omitted, 1, and multiple-key counts across string and integer keys
  • Added parity coverage for single-array array_diff, array_intersect, _key, and _assoc variants
  • Added coverage for date_get_last_errors() availability and consistency with DateTime::getLastErrors() / DateTimeImmutable::getLastErrors()

@TrixNEW

TrixNEW commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

LGTM 👍

@nvms
nvms merged commit f90022a into nvms:main Sep 21, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants