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

OOP Challenge extending classes

Challenge Task 2 of 3 Step 1: Add an additional array property to the Developer class named $skills that CANNOT be accessed from outside that class, but CAN be accessed by a child.

Step 2: Create a public facing GETTER named "getSkills" that will return the $skills property as an array.

Step 3: Create a public facing SETTER named "setSkills" that will accept an array and set the $skill property to that array value.


I got stuck here. I am quite new to PHP and not sure what I'm doing wrong and why.

<?php

class Developer extends User{
 protected $skills=[]; 
}
public function getSkills(){
 return $this->skills;
}
public function setSkills($array)
    {
    $this->skills = $array;
    }

?>

Less relevant:

<?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;
    }
}

2 Answers

Tim Knight
Tim Knight
28,888 Points

Hi Fiona,

From what I can tell looking at this it looks like the functions are outside of your Developer class. Take a look at that closing }.

<?php
class Developer extends User{
  protected $skills=[];

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

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

can you elaborate what is her mistake because same is happening with me

Pff haha yeah, that was the problem, thanks! This cost me hours.. :P