Skip to content

array_walk with printf callback bypasses TypeError for non-string format #19257

@sanmai

Description

@sanmai

Description

The following code:

<?php declare(strict_types=1);

$input = [1, 2, 3];
array_walk($input, printf(...));

Resulted in this output:

123

But I expected this output instead:

Fatal error: Uncaught TypeError: printf(): Argument #1 ($format) must be of type string, int given

By comparison, this code throws as expected:

<?php declare(strict_types=1);

$input = [1, 2, 3];
foreach ($input as $k => $i) {
    printf($i, $k);
}

PHP Version

PHP 8.4.10 (cli) (built: Jul  3 2025 12:35:27) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.10, Copyright (c), by Zend Technologies
    with Xdebug v3.4.2, Copyright (c) 2002-2025, by Derick Rethans

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions