Re: Recursive Static Method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Craige - In short, yes you can recursively call a static method. The
following code, for example, will work fine:

<?php

myClass::myStaticRecursiveMethod(0);

class myClass
{
public static function myStaticRecursiveMethod($x)
{
print $x++;

if($x < 10)
{
self::myStaticRecursiveMethod($x);
}
}
}

?>


However, you'll probably notice if you try it, that the example above only
calls the test() method twice. This is because it's using include_once, and
thus the code within the included file is only executed once. You'd need to
use include/require (not include_once/require_once) to make execute
repeatedly.

If this isn't your problem, and you're still having trouble, paste us the
code you're using (or a subset of it) and I'll have a look for you. :)

Dan


On Thu, Nov 13, 2008 at 7:52 AM, Yeti <yeti@xxxxxxxxxx> wrote:

> Some code would be quite helpful here. But your scenario should not
> make any problem.
>
> EXAMPLE:
> <?
> class foo {
>        static function test() {
>                static $count;
>                $count++;
>                echo "Call {$count}<br />";
>                include_once('test.php');
>        }
> }
> foo::test();
> ?>
>
> EXAMPLE (@file: test.php):
> <?php
> if (class_exists('foo')) {
>        foo::test();
> }
> exit();
> ?>
>
> OUTPUT:
> Call 1<br />Call 2<br />
>
> //A yeti
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux