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

Objects in PHP Forum

View Course » View Exercise

300 points
8176d0a9d675b403638039f2fe8f20d9?s=140&d=retro
Submitted by
Azrael.1987
about 3 years ago

4/10 error

<?php
class person {
public $isAlive = true;
public $firsname;
public $lastname;
public $age;
}
$teacher = new person();
$student = new person();
echo $teacher->isAlive;
?>
// 1

Oops, try again. Did you add the '$firstname', '$lastname' and '$age' properties?

What is wrong ?


2 votes

permalink

I get the same response. The code runs correctly, but it won't pass me.

<?php
// <!-- Your code here -->
class Person {
public $isAlive = true;
public $firstName;
public $lastName;
public $age;
}
$person1 = new Person();
$teacher = new Person();
$student = new Person();

    echo $teacher->isAlive;
    ?>

1359 points
53c554527c82ca4ea90055bb_758381632
Submitted by
Lee Giles
about 3 years ago

2 Comments

Picture Scott Marinoff about 3 years ago

I wrote my code like yours and it failed to pass until I changed the capitalization of my variables to $firstname, $lastname (without the capital 'N' in 'Name').

5384d03c282ae34d540037de_559832852 SUSHIL SUDHAKAR over 2 years ago

I had that too but it still didn't work. Sometimes you might have to refresh the screen.


1 vote

permalink

you are missing the "t" in $firstname

1040 points
345ce89fd1f040062dd9ec1cfc125387?s=140&d=retro
Submitted by
Brandon Meredith
about 3 years ago


1 vote

permalink

Same problem...

<!DOCTYPE html>
<html>
    <head>
      <title>Reconstructing the Person Class</title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
    </head>
    <body>
      <p>
        <?php

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

        $teacher = new Person();
        $student = new Person();
        echo $teacher->isAlive;        

        ?>
      </p>
    </body>
</html>

70 points
28587c12224c632c71a0e360ecfc4d84?s=140&d=retro
Submitted by
nlooman
about 3 years ago

1 Comment

28587c12224c632c71a0e360ecfc4d84?s=140&d=retro nlooman about 3 years ago

Fixed. No quotes around the true. http://www.codecademy.com/forum_questions/52df318d282ae3cc4f00166d

Thanks!!


1 vote

permalink

<?php
<!-- Your code here -->
class person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;

}
$teacher = new person();
$student = new person();
echo $teacher ->isalive
?>

121 points
8321c0b0ef4471299a85161c8ab4df3b?s=140&d=retro
Submitted by
liamhassall
about 3 years ago

1 Comment

48f7c6273c8ea9122aafb81080dd78a5?s=140&d=retro kyronae about 3 years ago

the "a" should be capitalized when you call isAlive, and you need to end the command with a semicolon.


1 vote

permalink

This didn't pass for me until I had an empty line after public $age.

2523 points
83a2b1f984333a629b002f9848f8fc73?s=140&d=retro
Submitted by
Covington Doan
about 3 years ago


0 votes

permalink

I should use "Person" not "person" :D

300 points
8176d0a9d675b403638039f2fe8f20d9?s=140&d=retro
Submitted by
Azrael.1987
about 3 years ago


0 votes

permalink

just change the isalive to isAlive and the firstname and last name to firstName and lastName and if it says did you add the first name last name age ,change them back,and if it says did you add the is alive then just change it back it works really

430 points
Picture
Submitted by
Graniti Bajraktari
about 3 years ago


0 votes

permalink

I was stuck on this question for at least 40 minutes. In the end, mine didn't work until I added the line: //<!-- Your code here --> below the opening PHP tag.

So, the following did NOT work:

<?php
    class Person {
        public $isAlive = true;
        ...

but this did:

<?php
// <!-- Your code here -->
    class Person {
        public $isAlive = true;
        ...

585 points
52aa18a1631fe96ce40003d6_10176043
Submitted by
Oz
about 3 years ago


0 votes

permalink

This works. I had to comment out the <!-- part with // and make sure that $firstname and $lastname were type not-camel case. As in, not $firstName (habit).

<!DOCTYPE html>
    <html>
        <head>
          <title>Reconstructing the Person Class</title>
          <link type='text/css' rel='stylesheet' href='style.css'/>
        </head>
        <body>
          <p>
          <?php
            //<!-- Your code here -->
            class Person {
                public $isAlive = true;
                public $firstname;
                public $lastname;
                public $age;

            }

            $teacher = new Person();
            $student = new Person();

            echo $teacher->isAlive;
          ?>
          </p>
        </body>
    </html>

646 points
93c6b3d0a4e3a973c4c377c5d3834838?s=140&d=retro
Submitted by
Matt Mazur
about 3 years ago

3 Comments

C01e379819e288c73548617f2dd4a1ce?s=140&d=retro Benjamin Kramarczuk almost 3 years ago

thanks

C01e379819e288c73548617f2dd4a1ce?s=140&d=retro Benjamin Kramarczuk almost 3 years ago

nonsense

54b67cf09113cb3a8d00561b_555229787 mikrocheez over 2 years ago

Yep. I had uppercase N's. That one cost me my coding streak.


0 votes

permalink

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

}
$teacher = new person();
$student = new person();
echo $teacher -> isalive: () ?>

614 points
Fd47cd6a57baa767289928d21b715fc7?s=140&d=retro
Submitted by
tommybrabble
over 2 years ago