note 130119 added to function.array-map

From: Date: Thu, 06 Mar 2025 11:38:45 +0000
Subject: note 130119 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-221947@lists.php.net to get a copy of this message
Something that's undocumented is what happens if the callback is an invalid function. <?php var_dump( array_map( 'invalid_callback', ['1', '2', '3'] ) ); ?> In PHP 7.4 and earlier it generates a warning and returns null Warning: array_map() expects parameter 1 to be a valid callback, function 'invalid_callback' not found or invalid function name in /tmp/array_map_test.php on line 5 NULL In PHP8.0 and later it generates a fatal error Fatal error: Uncaught TypeError: array_map(): Argument #1 ($callback) must be a valid callback, function "invalid_callback" not found or invalid function name in /tmp/array_map_test.php:5 Stack trace: #0 /tmp/array_map_test.php(5): array_map('invalid_callbac...', Array) #1 {main} thrown in /tmp/array_map_test.php on line 5 Process exited with code 255. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 77.103.156.2) ---- Manual Page -- https://php.net/manual/en/function.array-map.php Edit -- https://main.php.net/note/edit/130119 Del: integrated -- https://main.php.net/note/delete/130119/integrated Del: useless -- https://main.php.net/note/delete/130119/useless Del: bad code -- https://main.php.net/note/delete/130119/bad+code Del: spam -- https://main.php.net/note/delete/130119/spam Del: non-english -- https://main.php.net/note/delete/130119/non-english Del: in docs -- https://main.php.net/note/delete/130119/in+docs Del: other reasons-- https://main.php.net/note/delete/130119 Reject -- https://main.php.net/note/reject/130119 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221947) next »