Skip to content

Stdlib: str_decrement('a') — must return backtick not out-of-range Error (ext/standard/string.c) #10828

Description

@PurHur

Summary

str_decrement('a') must return ` (single-byte decrement below 'a'). This compiler throws:

Error: str_decrement(): Argument #1 ($string) "a" is out of decrement range

Multi-character strings like 'aa''z' and 'ba''az' work; only single lowercase 'a' is wrong.

Repro

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_str_decrement_single_a.php

Zend (PHP 8.3+): prints ` and exits 0.

This compiler: Error: … "a" is out of decrement range, exit 1.

php-src reference

  • ext/standard/string.cphp_str_decrement() single-character path decrements 'a' to `

Implementation (PHP-in-PHP)

  • ext/standard/VmString.phpstrDecrement() carry/trim logic mishandles lone 'a' (wraps to 'Z' then rejects). Match php-src per-byte decrement for length-1 strings.
  • ext/standard/str_decrement.php + JIT lowering if present.

Done when (php-src-strict)

  • php bin/vm.php test/repro/maintainer_gap_str_decrement_single_a.php exits 0.
  • Compliance guard for str_decrement('a') === `.

Related: #4218, #9277 (other str_increment/decrement edges).

Refs #1492

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions