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 Inheritance Extend a Class

Create a public facing SETTER named "setSkills" that will accept an array and set the $skill property to that arrayvalue

class Developer extends User{ protected $skills=array();

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

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

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

//add new child class here
class Developer extends User{
  $protected $skills=array();

  public function getSkills(){
    return $this->skills;
  }
  public function setSkills($array)
  {
    $this->skills = $array;
  }
} 
jamesjones21
jamesjones21
9,260 Points

what is the problem here?

Melissa Spiegel
Melissa Spiegel
Courses Plus Student 1,753 Points

protected should not have a $ it should be

<?php
//add new child class here
class Developer extends User{

  protected $skills = array();

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

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

1 Answer

Charles Fields
Charles Fields
4,205 Points

Your code is almost identical to mine, which was accepted as Task 2. (I'm looking only at the child class). I used the name $newSkills rather than $array as the input parameter. Might there be a problem with that name? What is the error message?

Btw, I came to this post looking to see if anyone was thrown off by the instruction to "set the $skill property", should be $skills.

Yes, "set the $skill property" confused me too!