<?php
class MyClass{
function __construct(){
// do something
}
function MyClass()
{
$args = func_get_args();
call_user_func_array(array(&$this, ‘__construct’), $args);
}
}
//or
class MyClass{
function __construct(){
$this->MyClass()
}
function MyClass()
{
// do something
}
}
?>
Refactorings
No refactoring yet !
Fabrice Luraine
November 9, 2007, November 09, 2007 18:13, permalink
I think the first one is preferable: it's better to write for php5 and keep a backward compatibility for php4
Hubert Roksor
November 11, 2007, November 11, 2007 02:41, permalink
Actually, I would use neither because defining two potential constructors generates a E_STRICT notice in PHP5. I would only define one constructor, PHP4 style.
Note that I would strongly advise pondering the development of a PHP4 application considering its imminent death. OOP is a real pain in PHP4 and you wouldn't exploit any of PHP5's strengths.
jim
January 28, 2008, January 28, 2008 15:56, permalink
<?php
class MyClass{
function __construct(){
// do something
}
function MyClass()
{
$args = func_get_args();
call_user_func_array(array(&$this, ‘__construct’), $args);
}
}
//or
class MyClass{
function __construct(){
$this->MyClass()
}
function MyClass()
{
// do something
}
}
?>
Which one is the best cross version php 4/5 constructor?