Skip to content

Stdlib: chop() / pos() — legacy aliases of rtrim() / current() (ext/standard/string.c, array.c) #4965

Closed

Description

@PurHur

Category

stdlib

Problem

Zend registers legacy aliases still used in older code and php-src tests:

Alias Target
chop() rtrim()
pos() current()

This compiler implements rtrim() / current() (via #3312 tracker for current) but function_exists('chop') and function_exists('pos') are false on bin/vm.php.

php-src reference

  • ext/standard/string.c — PHP_FUNCTION(chop) → php_rtrim()
  • ext/standard/array.c — PHP_FUNCTION(pos) → php_current()

Repro (today)

<?php
var_dump(function_exists('chop'), function_exists('pos'));
echo chop("  hi  "), "\n";
$a = [10 => 'x', 20 => 'y'];
reset($a);
echo pos($a), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php
'
Runtime chop / pos exist Sample output
Zend true / true hi / x
VM false / false undefined function

Scope (this repo)

Module Path
Aliases thin wrappers in ext/standard/chop.php, pos.php delegating to rtrim / current builtins
Registry ext/standard/Module.php
Depends on #3312 (current() / internal pointer) for pos() behavior

Done when

Links

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 3, 2026
  2. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    Merged via #7696.

    What shipped: chop() registered as string_rtrim('chop') alias (php-src ext/standard/string.c). pos() was already present.

    Verification (Docker):

    • function_exists('chop') / function_exists('pos') → true on VM and Zend
    • ./vendor/bin/phpunit --filter "chop|chop_pos" → OK (8 tests)
    • php bin/compile.php -l test/fixtures/aot/compile-only/chop_pos_aliases.php → exit 0
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:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions