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

Objects in PHP Forum

View Course » View Exercise

400 points
4eb3960f78b6aefdd611abf263056951?s=140&d=retro
Submitted by
sentamu
about 2 years ago

5/10: can't echo 30. Someone????

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("Mike", "Johnson", 30);

        echo $student-> age;
        }

0 votes

permalink

you need another underscore before construct

1123 points
Picture
Submitted by
Josh Berl
about 2 years ago

2 Comments

5562bf1293767618c00004f3_39392218 Anjuna about 2 years ago

^^ He's right

Picture Michael Bean Beatty about 2 years ago

DAYUM!


0 votes

permalink

thax, am on it!

400 points
4eb3960f78b6aefdd611abf263056951?s=140&d=retro
Submitted by
sentamu
about 2 years ago


0 votes

permalink

count your } , there is one too much in this post...
line 1 , class person { and line 11 } belong to each other, i dont know what line 19 } is doing there?

206 points
Picture
Submitted by
John Basten
about 2 years ago


0 votes

permalink

<!-- Your code here -->

<?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("Ayan", "Chakraborty", 25);
           echo $student->age;
        ?>

868 points
55584df5d3292fccf20003eb_676083776
Submitted by
Ayan Chakraborty
almost 2 years ago