note 125213 added to functions.arrow

From: Date: Mon, 27 Jul 2020 06:58:24 +0000
Subject: note 125213 added to functions.arrow
Groups: php.notes 
Request: Send a blank email to php-notes+get-214897@lists.php.net to get a copy of this message
In example 4 (Values from the outer scope cannot be modified by arrow functions) <?php $x = 1; $fn = fn() => $x++; // Has no effect $fn(); var_export($x); // Outputs 1 ?> Here we can use reference variable in fn(&$x) and pass the value from function call $fn($x) so that we will get the output as expected with out using Anonymous functions. Example: <?php $x = 1; $fn = fn(&$x) => $x++; $fn($x); var_export($x); ?> Output : 2 (as expected) But here it will not take values from parent scope automatically but we have to pass them explicitly. ---- Server IP: 45.112.84.4 Probable Submitter: 195.138.250.34 (proxied: 2409:4070:4e07:620c:199c:d968:c1b1:d131) ---- Manual Page -- http://php.net/manual/en/functions.arrow.php Edit -- https://master.php.net/note/edit/125213 Del: integrated -- https://master.php.net/note/delete/125213/integrated Del: useless -- https://master.php.net/note/delete/125213/useless Del: bad code -- https://master.php.net/note/delete/125213/bad+code Del: spam -- https://master.php.net/note/delete/125213/spam Del: non-english -- https://master.php.net/note/delete/125213/non-english Del: in docs -- https://master.php.net/note/delete/125213/in+docs Del: other reasons-- https://master.php.net/note/delete/125213 Reject -- https://master.php.net/note/reject/125213 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214897) next »