note 119388 added to functions.anonymous

From: Date: Wed, 25 May 2016 19:46:42 +0000
Subject: note 119388 added to functions.anonymous
Groups: php.notes 
Request: Send a blank email to php-notes+get-205588@lists.php.net to get a copy of this message
Will result in a "Parse error: syntax error, unexpected '[', expecting ',' or ')' ... " <?php $fruits = ['apples', 'oranges']; $example = function () use ($fruits[0]) { echo $fruits[0]; }; $example(); ?> Would have to do this: <?php $fruits = ['apples', 'oranges']; $example = function () use ($fruits) { echo $fruits[0]; // will echo 'apples' }; $example(); ?> Or this instead: <?php $fruits = ['apples', 'oranges']; $fruit = $fruits[0]; $example = function () use ($fruit) { echo $fruit; // will echo 'apples' }; $example(); ---- Server IP: 72.52.91.14 Probable Submitter: 101.59.230.27 ---- Manual Page -- http://php.net/manual/en/functions.anonymous.php Edit -- https://master.php.net/note/edit/119388 Del: integrated -- https://master.php.net/note/delete/119388/integrated Del: useless -- https://master.php.net/note/delete/119388/useless Del: bad code -- https://master.php.net/note/delete/119388/bad+code Del: spam -- https://master.php.net/note/delete/119388/spam Del: non-english -- https://master.php.net/note/delete/119388/non-english Del: in docs -- https://master.php.net/note/delete/119388/in+docs Del: other reasons-- https://master.php.net/note/delete/119388 Reject -- https://master.php.net/note/reject/119388 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205588) next »