468,249 Members | 1,509 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

PHP4 vs 5 programming

Hi

Since PHP5 classes use the __constructor() method, and PHP4 still
requires the classname as constructor, is there an easy way to
incorporate both in my class definitions so the class is usable in both
versions?

I know php5 will look for an old style constructor if there is no
__constructor definition, but I am convinced this will be deprecated in
future versions...

KR
Schraalhans
Feb 13 '06 #1
3 2239
Schraalhans Keukenmeester wrote:
Hi

Since PHP5 classes use the __constructor() method, and PHP4 still
requires the classname as constructor, is there an easy way to
incorporate both in my class definitions so the class is usable in both
versions?

I know php5 will look for an old style constructor if there is no
__constructor definition, but I am convinced this will be deprecated in
future versions...


You could try doing something like:

class MyClass {
function __construct () {
$this->MyClass ();
}
}

I am personally starting to move over to PHP5 breaking PHP4 compat. ;)

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Feb 13 '06 #2
On Mon, 13 Feb 2006 18:49:52 +0100, Schraalhans Keukenmeester
<no**@nowhere.nil> wrote:
Hi

Since PHP5 classes use the __constructor() method, and PHP4 still
requires the classname as constructor, is there an easy way to
incorporate both in my class definitions so the class is usable in both
versions?


Nothing is stopping you from declaring both... one will be called in
PHP4, the other in PHP5. You can then make a call from one to the
other, if you like.

Feb 13 '06 #3
Wayne wrote:
Nothing is stopping you from declaring both... one will be called in
PHP4, the other in PHP5. You can then make a call from one to the
other, if you like.


Yep. Only thing is, you get a "strict" warning for redeclaring the
constructor in php5.

--
E. Dronkert
Feb 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tim Tyler | last post: by
2 posts views Thread by Stefan Huber | last post: by
7 posts views Thread by Mathieu Maes | last post: by
12 posts views Thread by Drazen Gemic | last post: by
2 posts views Thread by mun | last post: by
8 posts views Thread by FFMG | last post: by
14 posts views Thread by Jeff | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.