Search code examples
phploopsscoperesolutioninfinite

scope resolution operator - infinite loop?


Would this code generate an infinite loop?

class one{
    function ex() {
        echo "Looptext";
        one::ex2();
    }
    function ex2() {
        one::ex();
    }
}  

$one = new one;
$one->ex2();  

I'm learning OO in php programming...


Solution

  • The two functions end up calling each other, which results in the infinite "loop" (it's not really a loop, but the result is an infinite number of method calls).

    ex2() - initial call - calls ex() - calls ex2() again - calls ex() again

    ... infinite loop.