Skip to content

Fix implode($array, null) throwing on the frameless call path - #25199

Open
b84330808 wants to merge 1 commit into
php:PHP-8.4from
b84330808:fix/implode-frameless-array-null
Open

b84330808 wants to merge 1 commit into
php:PHP-8.4from
b84330808:fix/implode-frameless-array-null

Conversation

@b84330808

Copy link
Copy Markdown

This change and the description below were written by an LLM (Claude Code).

PHP_FUNCTION(implode) accepts an array as the first argument when the second is null, which is the same as implode($array), and the stub allows it (string|array $separator, ?array $array = null). The frameless variant that direct two-argument calls compile to parses argument 1 as a string unconditionally, so whether the call works depends on how it's made:

$a = ['a', 'b'];
implode($a, null);                    // TypeError: implode(): Argument #1 ($separator) must be of type string, array given
call_user_func('implode', $a, null);  // "ab"
join($a, null);                       // "ab" (the alias isn't frameless)

implode($a, 'x') also blames argument 1, while the regular function reports Argument #2 ($array) must be of type ?array, string given.

The fix handles an array first argument the way the regular function does.

The new phpt fails without the fix. It passes with it, also under opcache with function and tracing JIT, along with ext/standard/tests/strings and Zend/tests/frameless*.

This is a regression in 8.4, where frameless calls were introduced. 8.3 only has the regular function, which accepts this call. Targeting PHP-8.4. The diff also applies to master.

PHP_FUNCTION(implode) accepts an array as the first argument when the
second one is null, which is the same as implode($array). The frameless
variant used for direct two-argument calls parsed argument 1 as a string
unconditionally, so the same call threw depending on how it was made:

    implode(['a', 'b'], null);                     // TypeError
    call_user_func('implode', ['a', 'b'], null);   // "ab"

It also blamed argument 1 for implode($array, 'x'), while the regular
function reports that argument 2 must be of type ?array.

Handle an array first argument the way the regular function does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant