Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Extending Object-Oriented PHP Extending the Family Sibling Relationships

Corey Lyons
Corey Lyons
24,684 Points

Object Oriented PHP Sibling Relationships Task 2

Within the Client class, extend the constructor method from the parent to allow the company to be included with initialization. I am confused on this challenge on exactly what I need to do. With my current code, it gives me the message I do not see a third parameter. The code is in Client.php

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 displayCompany() {
    return $this->getCompany();
  }

}

3 Answers

in the client class constructor ,try adding the $name,$title and $company parameters .that should at least deal with the 3rd parameter missing issue .i just tried this code and it worked.hope it does for you too

class Client extends User{

protected $company ;

public function __construct($name = null,$title = null, $company = null){ //uncomments code below after problem resolved for second part of challenge

//parent::__construct($name,$title);
//$this->company = $company ;

}

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

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

Corey Lyons
Corey Lyons
24,684 Points

It is still giving me the same error!

Corey Lyons
Corey Lyons
24,684 Points

I figured it out thank you!

you welcome ,what was the problem

Corey Lyons
Corey Lyons
24,684 Points

underscores in the construct function and the call to the parent