#28827 [NoF->Csd]: The example PHP code in docs http://php.net/gmp/ crashes PHP
| From: | vrana@php.net | Date: | Tue, 11 Jan 2005 17:20:23 +0000 |
| Subject: | #28827 [NoF->Csd]: The example PHP code in docs http://php.net/gmp/ crashes PHP | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969365923@lists.php.net to get a copy of this message | ||
ID: 28827
Updated by: vrana@php.net
Reported By: valyala at tut dot by
-Status: No Feedback
+Status: Closed
Bug Type: Documentation problem
Operating System: any
PHP Version: 4.3.7
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2004-06-28 01:00:02] phpdoc at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
[2004-06-18 12:40:38] tony2001@php.net
The example from docs works perfectly with latest PHP5 & PHP4.
Concerning stack overflows, read php-dev archives.
For example this post:
http://lists.php.net/article.php?group=php.internals&article=8851
and all the tread:
http://lists.php.net/article.php?group=php.internals&article=8840
Short version: this is expected behaviour.
------------------------------------------------------------------------
[2004-06-18 12:23:54] valyala at tut dot by
Description:
------------
The following example code, which "will calculate factorial of 1000
(pretty big number) very fast" on documentation page
http://php.net/gmp/ crashes PHP.
-------------------------------
<?php
function fact($x)
{
if ($x <= 1) {
return 1;
} else {
return gmp_mul($x, fact($x-1));
}
}
echo gmp_strval(fact(1000)) . "\n";
?>
-------------------------------
The next PHP code avoids the crash:
-------------------------------
<?php
function fact($x) {
$result = 1;
while ($x > 1) {
$result = gmp_mul($result, $x--);
}
return $result;
}
echo gmp_strval(fact(1000)) . "\n";
}
?>
-------------------------------
This bug related to the following bugs: #7720, #15522, #26212.
It seems that PHP4.3.7 (and older) don't handle stack overflow during
function calls.
You can find the maximum recursion depth for your version of PHP
independently. Just play with $rec_depth number in the following
script:
---------------------------
<?php
function f($n) {
if (--$n) f($n);
}
/* adjust this number to find the
maximum recursion depth
*/
$rec_depth = 1000;
f($rec_depth);
?>
---------------------------
p.s. Are the volunteers in PHP developement team, who wanted to track
stack overflow problem?
Reproduce code:
---------------
see above
Expected result:
----------------
decimal view of 1000!
Actual result:
--------------
PHP crash
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28827&edit=1