note 128742 added to function.array-map

From: Date: Tue, 18 Jul 2023 11:57:58 +0000
Subject: note 128742 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-220702@lists.php.net to get a copy of this message
If the callback function to be called is a static method from a different namespace, the fully qualified method including namespace must be specified (a use statement is not sufficient to resolve the namespace of the callback function) <?php use MyTools; $arr = [1, 2, 3]; $arr = array_map('Tools::myHelper', $arr); ?> will cause TypeError: array_map() expects parameter 1 to be a valid callback, class 'Tools' not found. Use the fully qualified name for the callback instead: <?php $arr = [1, 2, 3]; $arr = array_map('\MyTools\Tools::myHelper', $arr); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.168 (proxied: 94.217.40.132) ---- Manual Page -- https://php.net/manual/en/function.array-map.php Edit -- https://main.php.net/note/edit/128742 Del: integrated -- https://main.php.net/note/delete/128742/integrated Del: useless -- https://main.php.net/note/delete/128742/useless Del: bad code -- https://main.php.net/note/delete/128742/bad+code Del: spam -- https://main.php.net/note/delete/128742/spam Del: non-english -- https://main.php.net/note/delete/128742/non-english Del: in docs -- https://main.php.net/note/delete/128742/in+docs Del: other reasons-- https://main.php.net/note/delete/128742 Reject -- https://main.php.net/note/reject/128742 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220702) next »