PHP4 and Constructor

PHP4 and Constructor

am 04.10.2007 06:11:22 von T K

Hi,

I would like to use constructor in PHP4, but how do you make a constructor?
In PHP5, I do like

class ClassName {
function __construct() {
.....
}
}

But PHP4 doesn't have such a thing as __construct()... Reading the
official manual didn't make me understood. Does this mean the very
first `function` in class is always the constructor for the Class?

Tek

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP4 and Constructor

am 04.10.2007 06:18:06 von dmagick

T K wrote:
> Hi,
>
> I would like to use constructor in PHP4, but how do you make a constructor?

Name the function the same as the class.

class ABC {
function ABC() {
//constructor in php4
$this->__construct(); // just call the php5 one.
}
function __construct() {
//constructor in php5.
}
}


--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP4 and Constructor

am 04.10.2007 06:22:52 von jmolline

--------------030902050600040106050608
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

Hi,
In PHP4, the constructor has the same name as the class.

class ClassName {
function ClassName() {
....
}
}


T K a =E9crit :
> Hi,
>
> I would like to use constructor in PHP4, but how do you make a construc=
tor?
> In PHP5, I do like
>
> class ClassName {
> function __construct() {
> ....
> }
> }
>
> But PHP4 doesn't have such a thing as __construct()... Reading the
> official manual didn't make me understood. Does this mean the very
> first `function` in class is always the constructor for the Class?
>
> Tek
>
> =20

--------------030902050600040106050608--

Re: PHP4 and Constructor

am 04.10.2007 06:36:39 von Joseph Crawford

this is why for backwards compatibility with PHP 4 people usually do
this. Note that if you use public/private/protected it probably will
not work on PHP 4

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

function Foo($params)
{
// Actual Constructor
}
}
?>

On 10/4/07, Jean Mollin=E9 wrote:
> Hi,
> In PHP4, the constructor has the same name as the class.
>
> class ClassName {
> function ClassName() {
> ....
> }
> }
>
>
> T K a =E9crit :
> > Hi,
> >
> > I would like to use constructor in PHP4, but how do you make a construc=
tor?
> > In PHP5, I do like
> >
> > class ClassName {
> > function __construct() {
> > ....
> > }
> > }
> >
> > But PHP4 doesn't have such a thing as __construct()... Reading the
> > official manual didn't make me understood. Does this mean the very
> > first `function` in class is always the constructor for the Class?
> >
> > Tek
> >
> >
>


--=20
Joseph Crawford Jr.
Zend Certified Engineer
http://www.josephcrawford.com/
1-315-820-4244
codebowl@gmail.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP4 and Constructor

am 04.10.2007 07:09:01 von T K

Thanks guys!

I got the same name trick for PHP 4 class constructor.

All the best,

T

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php