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

In the Developer.php file, add a Developer class that is a child of the User class

Bummer: syntax error, unexpected 'class' (T_CLASS), expecting function (T_FUNCTION) in User.php on line 4 need help here i tried

User.php
<?php
//do not modify this file
class User {
class Developer extends User 
{
  protected $skills = array();
  protected $name;

  public function getSkills(){
    return $this->skills;
  }
  public function setSkills($skill){
    $this->skills = $skill;  
  }
  public function displayUserSkills(){
    $name = $this->name;
    $userSkills = implode(', ', $this->skills);
    return "$name has the following skills: $userSkills";
  }
}
Developer.php
<?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;
}
}

2 Answers

jamesjones21
jamesjones21
9,248 Points

Hi,

the user class has the Developer class mentioned in it, you will need to remove this, also there is a comment in the User class to not modify. So you will only need to modify the Developer.php file.

The User.php needs to remain as the following:

<?php
//do not modify this file
class User {
class Developer extends User 
{
  protected $skills = array();
  protected $name;

  public function getSkills(){
    return $this->skills;
  }
  public function setSkills($skill){
    $this->skills = $skill;  
  }
  public function displayUserSkills(){
    $name = $this->name;
    $userSkills = implode(', ', $this->skills);
    return "$name has the following skills: $userSkills";
  }
}

thanks it worked so well