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

Objects in PHP Forum

View Course » View Exercise

239 points
B09e5a752e0ccb159b4d9b12eb58a5e9?s=140&d=retro
Submitted by
31349527
about 3 years ago

8/10 tutorial completion check

This isn't a question, it's more of a note to whoever wrote/is managing the tutorials in this section that if in the code below you've written __constructor instead of __construct the tutorial will return a "Way to go!" message and let you continue instead of pointing out that there's something wrong.

If you've written __constructor the output will be "Woof!" and "Hello, my name is ." without returning the name because both names will be null.

<?php 
    class Dog {
        public $numLegs = 4;
        public $name;

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

        public function bark() {
           return 'Woof!';
        }

        public function greet() {
            return 'Hello, my name is ' . $this->name . '.';
        }
    };

    $dog1 = new Dog('Barker');
    $dog2 = new Dog('Amigo');

    echo $dog1->bark() . '<br>';
    echo $dog2->greet();
?>

0 votes

permalink

Thanks alot for this bruv, i was wondering what i did wrong.

1027 points
54e4e1e851b887a2cb00393a_785108375
Submitted by
Abdullah Shahid
about 3 years ago


0 votes

permalink

Thank you.

788 points
532afe767c82caf100002734_506113534
Submitted by
Thinnling
almost 3 years ago


0 votes

permalink

Thankyou :) !

246 points
551e59fdd3292f64230003d3_274442103
Submitted by
Yasmine
over 2 years ago