note 126217 added to language.variables.scope
| From: | admin at shenjinpeng dot cn | Date: | Mon, 05 Jul 2021 03:57:37 +0000 |
| Subject: | note 126217 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216576@lists.php.net to get a copy of this message | ||
<?php
function foo(){
static $a= 0;
$bar = function(){
global $a ;
return ++$a;
};
return $bar();
}
echo foo(); // 1
echo foo(); // 2
function foo1(){
$bar = function(){
static $a = 0;
return ++$a;
};
return $bar();
}
echo foo1() ; // 1
echo foo1() ; // 1
function foo2(){
static $a = 0;
$bar = function() use (&$a){
return ++$a;
};
return $bar();
}
echo foo2() ; // 1
echo foo2() ; // 2
function foo3($func){
static $a = 0;
return $func($a);
}
echo foo3(fn(&$a) => ++$a ); // 1
echo foo3(fn(&$a) => ++$a ); // 2
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 116.52.2.62)
----
Manual Page -- https://php.net/manual/en/language.variables.scope.php
Edit -- https://main.php.net/note/edit/126217
Del: integrated -- https://main.php.net/note/delete/126217/integrated
Del: useless -- https://main.php.net/note/delete/126217/useless
Del: bad code -- https://main.php.net/note/delete/126217/bad+code
Del: spam -- https://main.php.net/note/delete/126217/spam
Del: non-english -- https://main.php.net/note/delete/126217/non-english
Del: in docs -- https://main.php.net/note/delete/126217/in+docs
Del: other reasons-- https://main.php.net/note/delete/126217
Reject -- https://main.php.net/note/reject/126217
Search -- https://main.php.net/manage/user-notes.php