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

Objects in PHP Forum

View Course » View Exercise

1058 points
E4637eca88efa1a8e65a99a26349bf42?s=140&d=retro
Submitted by
TritoneJapan
about 2 years ago

Bug? "Oops, try again. I don't see your constructor..."

Is this a bug or am I missing something? I do see "2" echoed in the mini-browser output. Thanks!

    <?php

    class Person {
        public $isAlive = true;
        public $firstname;
        public $lastname;
        public $age;

        public function __construct($firstname, $lastname, $age) {
            $this->firstname = $firstname;
            $this->lastname = $lastname;
            $this->age = $age;
        }

    }
    $teacher = new Person("boring","12345",12345);
    $student = new Person("super","dude",2);
    echo $student->age;
    ?>

0 votes

permalink

I don't see any problems in your code, but you can try pasting mine
<?php
class Person{
public $isAlive = true;
public $firstname;
public $lastname;
public $age;

    public function __construct($firstname, $lastname, $age){
        $this->firstname = $firstname;
        $this->lastname = $lastname;
        $this->age = $age;
    }
   }

   $teacher = new Person("boring", "asd", 12345);
   $student = new Person("boring", "12345", 12345);
   echo $student->age;
   ?>

728 points
C249586106a69761a4cf20a61ab5eedf?s=140&d=retro
Submitted by
mzmitrulevicius
about 2 years ago

1 Comment

71c15ab76387ac5ba6529a80914cede8?s=140&d=retro Ruben van Houten almost 2 years ago

I guess they expect you to use the "->", method and and keywords. Time to try something else.