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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.