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

Objects in PHP Forum

View Course » View Exercise

1142 points
52605615f10c605228002abc_770166181
Submitted by
Rich Girou
over 3 years ago

I keep getting a T_CLASS / T_VARIABLE error but it passes. Why?

 <?php 
   class Person {
    public class $isAlive = true;
    public class $firstname;
    public class $lastname;
    public class $age;
   }
   $teacher = new Person();
   $student = new Person();
   echo $teacher->isAlive;
   ?>

2 votes

permalink

why don't you remove "class" from "public class $isAlive".
I think it may work.

such as....
public $isAlive = true;

1650 points
C72926abb939a492947cc8642e20c62f?s=140&d=retro
Submitted by
김구
over 3 years ago


1 vote

permalink

You supposed to put just "public" instead of "class public" because your class is the object/ the "Person: you've created. When adding properties to your class, you wanna type "public" so the information is available. Another way to think of it would be think of it would be to use say cats. There are many different types of cats. Each cat (object) with its own characteristics (proprieties) like how tall or short it is. If you wanted everyone to know about your cat's(object) characteristic (properties) then you'd wanna say that they are "public".. Makes any sense?

544 points
Picture
Submitted by
DM Suja
over 3 years ago


0 votes

permalink

I'm experiencing the same issue in Chrome and Safari.

585 points
51c3151d9c4e9dffc500ab62_907785280
Submitted by
kenfager
over 3 years ago


0 votes

permalink

same here... I checked and checked... i think i'm doing it right...

309 points
5282d7a2f10c60128d001107_510456202
Submitted by
bloodOrange
over 3 years ago