Something I don't understand about PHP classes

From: Date: Sat, 09 May 2009 16:35:04 +0000
Subject: Something I don't understand about PHP classes
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-292422@lists.php.net to get a copy of this message
Ok, I suppose that this should be a very simple problem and probably the answer is obvious, but I really can't understand how the classes and the rest of the stuff works in PHP... Let's suppose that we have this piece of code: <?php
    class Duck {
    	
function __construct() { while(1==1) { // This is an infinite loop } }
    }
echo "Hello world..."; $DonaldDuck = new Duck(); ?> I have put an infinite loop in the class constructor just to introduce a problem that will halt the execution of the PHP code. Now, If I run this code I would expect that the PHP interpreter would print the "Hello world..." string, and then it should call the class constructor with the infinite loop inside of it. But that doesn't happen. Instead, the PHP interpreter enters IMMEDIATELY into an infinite loop, as if the variables were declared immediately and then the rest of the code is executed. Is it right? Because I'm having really hard times in debugging a PHP class

« previous php.general (#292422) next »