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

BOHAN ZHANG
BOHAN ZHANG
4,446 Points

PHP stuck

Extending from a parent class allows the child to inherit all attributes and abilities of the parent. Step 1: Add a new method to the Developer class named displayUserSkills. Step 2: Use the 'name' from the PARENT class, and the 'skills' from the CURRENT class, to replace the <PLACEHOLDERS> and RETURN following string (NOTE that skills separated with a comma and space): <NAME> has the following skills: <SKILL1>, <SKILL2>, <SKILL3> Example Output: Alena has the following skills: PHP, MySQL, HTML

my code so far:

<?php

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

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

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

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

}

}

$an_array = array("PHP","MySQL","HTML");

$stuff = new Developer ;

$stuff -> setSkills($an_array);

$stuff -> setName('Alena');

echo $stuff->getName() . " has the following skills: " . implode(', ', $stuff->displayUserSkills());

?>

Out put error;

Alena has the following skills: PHP, MySQL, HTMLPHP Warning: strtolower() expects parameter 1 to be string, array given in 37235294-194c-4d9b-943d-c20e202f54c4.php on line 224 Warning: strtolower() expects parameter 1 to be string, array given in 37235294-194c-4d9b-943d-c20e202f54c4.php on line 224

anyone knows why?

3 Answers

Thi Kim Hong Dinh
Thi Kim Hong Dinh
11,238 Points

You don't need to display the output example. Here is my code for your reference.

<?php

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

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

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

  public function displayUserSkills()
  {
      return $this->name . " has the following skills: " . implode(", ", $this->getSkills());

  }

}

Hope this helps.

Kaisma Penn-Titley
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Kaisma Penn-Titley
PHP Development Techdegree Graduate 20,208 Points

This worked for me!

<?php

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

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

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

  public function displayUserSkills() {
    return $this->name . " " . "has the following skills: " . implode(", ", $this->getSkills());
  }
}