note 124792 added to functions.anonymous

From: Date: Wed, 04 Mar 2020 04:58:04 +0000
Subject: note 124792 added to functions.anonymous
Groups: php.notes 
Request: Send a blank email to php-notes+get-214280@lists.php.net to get a copy of this message
IIFE(Immediately-invoked function expression): Before PHP 7.0, you can use it by wrapping your anonymous function with call_user_func(). <?php $type = 'number'; var_dump( call_user_func( function() use ($type) { if ($type=='number') return [1,2,3]; else if ($type=='alphabet') return ['a','b','c']; } ) ); ?> Starting from PHP 7.0, you can use it by wrapping your anonymous function with ()(). <?php $type = 'number'; var_dump( ( function() use ($type) { if ($type=='number') return [1,2,3]; else if ($type=='alphabet') return ['a','b','c']; } )() ); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 93.95.185.109) ---- Manual Page -- http://php.net/manual/en/functions.anonymous.php Edit -- https://master.php.net/note/edit/124792 Del: integrated -- https://master.php.net/note/delete/124792/integrated Del: useless -- https://master.php.net/note/delete/124792/useless Del: bad code -- https://master.php.net/note/delete/124792/bad+code Del: spam -- https://master.php.net/note/delete/124792/spam Del: non-english -- https://master.php.net/note/delete/124792/non-english Del: in docs -- https://master.php.net/note/delete/124792/in+docs Del: other reasons-- https://master.php.net/note/delete/124792 Reject -- https://master.php.net/note/reject/124792 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214280) next »