note 125349 added to functions.user-defined
| From: | greenbluemoonlight at gmail dot com | Date: | Thu, 10 Sep 2020 22:58:23 +0000 |
| Subject: | note 125349 added to functions.user-defined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-215094@lists.php.net to get a copy of this message | ||
Notice that recursion($a+1) has the same output as ++a.
If recursion($a++) is mistakenly used instead of recursion(++$a),
The output is infinite loop.
<?php
////recursion($a + 1)
function recursion($a)
{
if ($a < 4) {
echo $a . "\n";
recursion($a + 1);
}
}
recursion(1);
//Outputs:
1
2
3
////recursion(++$a)
function recursion($a)
{
if ($a < 4) {
echo $a . "\n";
recursion(++$a);
}
}
recursion(1);
//Outputs:
1
2
3
////recursion($a++)
function recursion($a)
{
if ($a < 4) {
echo $a . "\n";
recursion($a++);
}
}
recursion(1);
//Outputs: INFINITE LOOP !!!
1
1
1
1
1..............
?>
----
Server IP: 45.112.84.4
Probable Submitter: 103.51.167.36 (proxied: 47.229.27.108)
----
Manual Page -- http://php.net/manual/en/functions.user-defined.php
Edit -- https://master.php.net/note/edit/125349
Del: integrated -- https://master.php.net/note/delete/125349/integrated
Del: useless -- https://master.php.net/note/delete/125349/useless
Del: bad code -- https://master.php.net/note/delete/125349/bad+code
Del: spam -- https://master.php.net/note/delete/125349/spam
Del: non-english -- https://master.php.net/note/delete/125349/non-english
Del: in docs -- https://master.php.net/note/delete/125349/in+docs
Del: other reasons-- https://master.php.net/note/delete/125349
Reject -- https://master.php.net/note/reject/125349
Search -- https://master.php.net/manage/user-notes.php