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

Objects in PHP Forum

View Course » View Exercise

1068 points
165fbd7214f0c8205c812d54022a62fa?s=140&d=retro
Submitted by
wtharris89
over 3 years ago

7/10 Putting it All Together: I can't figure out why I'm getting errors!

I keep getting errors. First it was telling me I hadn't added the <?php ?> tags when I already had on line 9. Now it's kicking back an error asking if I've created a $numlegs property. What is going on, am I missing something obvious here?

    <?php
    class Dog {
        public $numlegs = 4;
        public $name;
        public function __construct($name) {
            $this->name = $name;
        }
    }
    ?>

4 votes

permalink

change $numlegs should be $numLegs

323 points
B792f7b91709dcf839e685d34d0ebad1?s=140&d=retro
Submitted by
arsemesis_53e882269c4e9d20660061ce_d
over 3 years ago

2 Comments

Picture Ziana Nicole Mitchell about 3 years ago

on mine i already had the $numLegs but mine still doesn't work

5907fa2e58212277b80000b1_403915627 Thomas Gerot almost 3 years ago

That was my issue. Thanks!


1 vote

permalink

You need 2 underscores, not 1 in __construct()

719 points
Picture
Submitted by
Stewart Olson
about 3 years ago

1 Comment

Picture Norman over 2 years ago

Hi Stewart
your suggestion of 2 underscores works. Thank you


0 votes

permalink

this is my php code and it still gives me errors::

  <!-- Your code here -->
        <?php
        class Dog {
            public $numLegs = 4;
            public $name;

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

589 points
Picture
Submitted by
Ziana Nicole Mitchell
about 3 years ago

6 Comments

Picture Ziana Nicole Mitchell about 3 years ago

keeps telling me to make sure i have a function _construct() but as you can see i have it there. don't know what going on.

Picture Ziana Nicole Mitchell about 3 years ago

tried refreshing page and resubmitting but still same error message

5305b8297f1e2212e3610c8d2e97a50a?s=140&d=retro Ohla about 3 years ago

the compiler i think is not up to date!

Picture Zachary Burris almost 3 years ago

Also, I added a ";" to the end of the construct and it passed me, but the interpreter threw an error... so...

5907fa2e58212277b80000b1_403915627 Thomas Gerot almost 3 years ago

As for Zachs, If your code is fits the contentions, but it has no idea what the rest of the code is doing, it will still pass you,

5907fa2e58212277b80000b1_403915627 Thomas Gerot almost 3 years ago

Stewert's answer above is the solution to your problem.