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

B P
B P
4,563 Points

"Oops! It looks like Task 1 is no longer passing"

I already asked for help on this once, and got one answer, but it didn't help..

This code keeps returning error Oops! It looks like Task 1 is no longer passing", Task 1 was just making a class Subdivision and public property $houses in it. What the hell is going on???

index.php
<?php

// add code below this comment
class Subdivision {
  public $houses = []; 

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

4 Answers

Hi there!

You need to declare $matchingHouses inside of the filterHouseColor method. And put return statement inside of the method body.

class Subdivision {
  public $houses = []; 

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

Hope this will help.

Best regards!

B P
B P
4,563 Points

That still does not work though. Even tried completely copying your method, and that gives error "Bummer! Cannot use temporary expression in write context in index.php on line 10"

forgot about dollar sign in expression ;)

$matchingHouses[] = $house; 
B P
B P
4,563 Points

Yea, was just about to post about that. Works now.

You welcome )