Jump to content

extending php classes


corillo181

Recommended Posts

so i got a class with some methods and stuff..

 

<?php

class test1{
protected $id;
protected $name;

public function __construct($id,$name){
    $this->id = $id;
   $this->name = $name;
}

}
?>

 

i have done it before but i forgot how do i call it on a child class.

<?php
class test2 extends test1{
    
  public __construct($id,$name,$lastname){
  parent::__construct($id,$name); 
    $this->lastname = $lastname;
}

public function getfullname(){
    print "you are {$this->name},{$this->lastname}";

}
}
?>

 

can any one please tell me how to do it?

Link to comment
https://forums.phpfreaks.com/topic/67858-extending-php-classes/
Share on other sites

i'm just try find out how would i call properties in the parent to the child.

 

if i have a statment like

 

test1= new test1('1','Jay');

 

test2 = new test2('lastname');

 

test2->getfullname();

 

 

assuming the child class contrus tlooks like this

 

__construct(lastname){

parent::__construct($id,$name);

  $this->lastname;

}

Link to comment
https://forums.phpfreaks.com/topic/67858-extending-php-classes/#findComment-341114
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.