Page 1 of 1
PHP4/5 constructor differences
Posted: Wed Jul 20, 2005 4:03 pm
by Chris Corbyn
Hi,
Anybody else do this or have a reason not to?
Code: Select all
class whateverClass {
//PHP5's constructor
function __construct() {
//
}
//PHP4's constructor
function whateverClass() {
$this->__construct(); //Loop back into the PHP5 one
}
}
EDIT | Corrected rushed typos
Posted: Wed Jul 20, 2005 4:45 pm
by neophyte
I don't understand why you would? Why would you use PHP 5 object syntax in PHP 4 application. PHP 5 should pick up on old constructors just fine. Did I miss something?

Posted: Wed Jul 20, 2005 4:47 pm
by nielsene
Well I see how it allows the same script to run both places; but you still can take advantage of PHP5's features if you're trying for compatability with PHP4... so you still can use well-named super-class constuctors, etc...
So I don't see the point in this instance.
Posted: Wed Jul 20, 2005 4:59 pm
by neophyte
The manual:
For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics.
Posted: Wed Jul 20, 2005 5:37 pm
by Chris Corbyn
neophyte wrote:The manual:
For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics.
That'll teach me to RTFM
I literally just started using PHP5 lol
