28f4b93162bef554e624154514dd5bd6

Which one is the best cross version php 4/5 constructor?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?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 !

7cc9ea102594dee24a8dd54c5b7b2c81

Fabrice Luraine

November 9, 2007, November 09, 2007 18:13, permalink

1 rating. Login to rate!

I think the first one is preferable: it's better to write for php5 and keep a backward compatibility for php4

Ae0689b76b0fa370800323a71742c24f

Hubert Roksor

November 11, 2007, November 11, 2007 02:41, permalink

No rating. Login to rate!

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.

Avatar

jim

January 28, 2008, January 28, 2008 15:56, permalink

No rating. Login to rate!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?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
}

}

?>

Your refactoring





Format Copy from initial code

or Cancel