This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Objects in PHP Forum

View Course

659 points
4d5b74a840087e5aac9a1c56f6e6645a?s=140&d=retro
Submitted by
Yvette Obbink
almost 2 years ago

I can't figure out what's wrong with my code? 7/10

My code is as following:

  <?php
    class Dog{

    public $numlegs=4;
    public $name;

    public function __construct($name) {
        $this->name = $name;
    }
    };
    ?>

When I submit it, I get this message:
Oops, try again. Did you create an '$numLegs' property?

What's wrong?


0 votes

permalink

u shoud pass both the variables to the constructor ..like this

<?php
class Dog{

   public $numlegs=4;
   public $name;

      public function __construct($numLegs,$name) {

          $this->name = $name;
        }
  }

  ?>

389 points
Picture
Submitted by
kompalpaliwal
almost 2 years ago


0 votes

permalink

in $numLegs the "l" in legs must be "L"....

997 points
577c49966c20feab20000519_427494609
Submitted by
Jeff N Neely
almost 2 years ago


0 votes

permalink

Hi, here's mine. It passed. (The "oops" messages are not particularly detailed or helpful, I find.)

  <?php 
  class Dog {
    public $numLegs = 4;
    public $name;
    public function__construct($name){
    $this->name = $name;
    }
   ?> 

432 points
563f564eb62548d5c9000854_286301216
Submitted by
Darkhorse2
over 1 year ago