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 Object-Oriented PHP Basics Building a Collection Collection Objects

Leandro Botella Penalva
Leandro Botella Penalva
17,618 Points

Possible Code Challenge bug

Hi,

I don't know if this is a bug or not but I don't understand why in the Task 3 of the Challenge

https://teamtreehouse.com/library/objectoriented-php-basics-2/building-a-collection/collection-objects

using this code fails the task with "Bummer! To access the local $houses property, use $this->houses."

<?php

// add code below this comment
class Subdivision {
  public $houses = array();

  public function filterHouseColor($color)
  {
    $houses = array();
    foreach ($this->houses as $house) {
      if ($house->roof_color == $color || $house->wall_color == $color) {
        $houses[] = $house;
      }
    }
    return $houses;
  }
}

?>

While using this other works. I just changed the name of variable $houses inside the function.

<?php

// add code below this comment
class Subdivision {
  public $houses = array();

  public function filterHouseColor($color)
  {
    $anythingelse = array();
    foreach ($this->houses as $house) {
      if ($house->roof_color == $color || $house->wall_color == $color) {
        $anythingelse[] = $house;
      }
    }
    return $anythingelse;
  }
}

?>