Re: Parents constructor
| From: | Robert Cummings | Date: | Fri, 24 Mar 2006 05:57:38 +0000 |
| Subject: | Re: Parents constructor | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-232521@lists.php.net to get a copy of this message | ||
On Fri, 2006-03-24 at 00:40, Peter Lauri wrote:
> Hi,
>
> I have a class B that extends class A. I want to call constructor of A
> correctly, how to do that. This is how I tried:
>
> Class B extends A {
> Function B($Bvariable) {
> Parent::A($Bvariable);
> }
>
> }
>
> Class A {
> Function A($Avariable) {
> Dostuff...
> }
> }
>
> It does not seem correct, maybe I am correct, but I do not feel correct.
<?php
Class A
{
function __construct( $Avariable )
{
// Do stuff...
}
function A( $Avariable )
{
$this->__construct( $Avariable );
}
}
Class B extends A
{
function __construct( $Bvariable )
{
parent::__construct( $Bvariable );
}
function B( $Bvariable )
{
$this->__construct( $Bvariable );
}
}
?>
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'