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

Daniel Glennie
Daniel Glennie
42,854 Points

PHP Collections Code Challenge

I am struggling with this one. If I use $this->wall_color then I get an error about my if statement not having the correct logic but I can't see any problem with it. The order of operations should evaluate each condition before evaluating if either condition is true. If I use $house->wall_color then I get an error saying my return value needs to be a collection of house objects. Where am I going wrong here?

index.php
<?php

// add code below this comment
class Subdivision{
  public $houses = array();
  public function filterHouseColor($color){
    $lots = array();
    foreach($this->houses as $house){
      if ($house->wall_color == $color || $house->roof_color == $color){
        $lots[] = $house->lot;
      }
    }
    return $lots;
  }
}
?>

1 Answer

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Inside of the function filterHouseColor change this line of code

$lots[] = $house->lot;

to this

$lots[] = $house;

Inf first case, you are trying to save result of the field which doesn't exist. Eventualy you will get an error. You need to assign object like in second case.