note 118706 added to language.variables.scope

From: Date: Fri, 22 Jan 2016 08:26:45 +0000
Subject: note 118706 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-204746@lists.php.net to get a copy of this message
function myfunc($num) { static $result = 0; $num--; $result++; echo "num: $num result: $result" . "<br />"; if($result == 10) { return $result; } myfunc($num); } $a = myfunc(5); var_dump($a); /************************/ run code above, the result is: num: 4 result: 1 num: 3 result: 2 num: 2 result: 3 num: 1 result: 4 num: 0 result: 5 num: -1 result: 6 num: -2 result: 7 num: -3 result: 8 num: -4 result: 9 num: -5 result: 10 null Why the result value of this function is null? ---- Server IP: 72.52.91.14 Probable Submitter: 125.39.23.211 ---- Manual Page -- http://php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/118706 Del: integrated -- https://master.php.net/note/delete/118706/integrated Del: useless -- https://master.php.net/note/delete/118706/useless Del: bad code -- https://master.php.net/note/delete/118706/bad+code Del: spam -- https://master.php.net/note/delete/118706/spam Del: non-english -- https://master.php.net/note/delete/118706/non-english Del: in docs -- https://master.php.net/note/delete/118706/in+docs Del: other reasons-- https://master.php.net/note/delete/118706 Reject -- https://master.php.net/note/reject/118706 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204746) next »