Skip to content

Stdlib: grapheme_str_split() — PHP 8.4 grapheme cluster split (ext/intl/grapheme) #5958

Description

@PurHur

Category

stdlib · php-src-strict

Status (expanded 2026-06-06 — implementation-ready)

PHP 8.4 adds grapheme_str_split() (note underscore). Distinct from legacy grapheme_strsplit() tracked in #6246 — implement both names if php-src registers aliases; primary symbol is grapheme_str_split.

Problem

grapheme_str_split() is not implemented — function_exists('grapheme_str_split') is false. Zend splits a string into an array of grapheme clusters (Unicode extended grapheme cluster rules), distinct from byte/character str_split().

Complements #3352 umbrella and #5914 enum operand guards.

php-src reference

Repro

test/repro-maintainer/grapheme_str_split_missing.php:

<?php
declare(strict_types=1);

if (!function_exists('grapheme_str_split')) {
    fwrite(STDERR, "MISSING grapheme_str_split\n");
    exit(1);
}

// Single grapheme: e + combining acute
$one = grapheme_str_split("e\xCC\x81");
var_export($one);
echo "\n";

// ASCII — one grapheme per char
$ascii = grapheme_str_split('abc');
var_export($ascii);
echo "\n";

// Optional length argument (max graphemes per chunk) — Zend 8.4+
if (function_exists('grapheme_str_split')) {
    $chunked = grapheme_str_split('abcdef', 2);
    var_export($chunked);
    echo "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/grapheme_str_split_missing.php 2>/dev/null || echo "Zend: needs PHP 8.4+ intl"
php bin/vm.php test/repro-maintainer/grapheme_str_split_missing.php 2>&1 | head -5
'
Check Zend 8.4+ (intl) VM today
function_exists('grapheme_str_split') true false
grapheme_str_split("e\xCC\x81") array(1) { [0]=> string(3) ... } undefined function
grapheme_str_split('abc') three single-char strings undefined function
grapheme_str_split('abcdef', 2) chunked grapheme arrays undefined function

php-src-strict: enum case string operands must TypeError (#5914).

Scope

Area Files
ext ext/intl/grapheme_str_split.php — register in ext/intl/Module.php
VM PHP grapheme cluster boundaries (ICU or bundled table); no permanent C-only builtin
JIT/AOT VM-only v1 OK; document in capability matrix
Tests test/compliance/cases/stdlib/grapheme_str_split.phpt

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter grapheme_str_split'

Related

Activity

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