Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Extending Object-Oriented PHP Extending the Family Sibling Relationships

Corey Lyons
Corey Lyons
24,684 Points

Sibling Relationships Task 2

Within the Client class, extend the constructor method from the parent to allow the company to be included with initialization. It is giving me the error "I do not see a third parameter for company"

User.php
<?php
//do not modify this file
class User {
    protected $name;
    protected $title;

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

    public function __toString() {
        return $this->getSalutation();
    }

    public function getSalutation() {
        return $this->title . " " . $this->name;
    }

    public function getName() {
        return $this->name;
    }

    public function setName($name) {
        $this->name = $name;
    }

    public function getTitle() {
        return $this->title;
    }

    public function setTitle($title) {
        $this->title = $title;
    }
}
Developer.php
<?php
//do not modify this file
class Developer extends User 
{
  protected $skills;

  public function getSkills() {
      return $this->skills;
  }

  public function setSkills($array) {
      $this->skills = $array;
  }

  public function displayUserSkills() {
      return $this->getName() . ' has the following skills: ' . implode(", ", $this->skills);
  }
}
Client.php
<?php
//add code for Client class

class Client extends User {
  protected $company;

  public function getCompany() {
      return $this->company;
  }

  public function setCompany($array) {
      $this->company = $array;
  }

  public function construct ($name = null, $title = null, $company = null) { 
      parent::construct($name,$title); $this->setCompany($company);
  }

}

1 Answer

Patricia Hector
Patricia Hector
42,901 Points

When you call the constructor you need to do it like this

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

Once you add the underscores everything runs perfectly. Other examples of this behavior

__destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone()  __debugInfo()

Well knonw as Magic Methods.

Corey Lyons
Corey Lyons
24,684 Points

'''public function construct ($name = null , $title = null , $company = null ){ parent::construct($name,$title); $this->setCompany($company); }''' The underscores needed to be included with the first call to construct as well, I figured it out thank you very much!