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

Objects in PHP Forum

View Course » View Exercise

467 points
514e85a62acdd711100005f9_630708449
Submitted by
Tamara Evans
over 4 years ago

Solution if stuck on this exercise

This exercise is a bit annoying because although the directions tell you to do one thing, the solution is the opposite. To prevent others from getting as annoyed as I did, here's the solution that worked for me:

<?php
class Classname {
}
$teacher = new Classname();
$student = new Classname();
?>


18 votes

permalink

Hello,
although your code isn't correct it passes. :-(

The following code is the expected one:

    <?php
    class Person {

    }
    $teacher = new Person();
    $student = new Person();
    ?>

3108 points
5154c6cf115b457ac9000021_667301409
Submitted by
boring12345
over 4 years ago

4 Comments

48cccd070ffc9268266a43ac0ba85552?s=140&d=retro pp219 over 4 years ago

When do you know to use the { } symbols?

I thought it was:

<?php
class Person {
$teacher = new Person();
$student = new Person();
}
?>

5154c6cf115b457ac9000021_667301409 boring12345 over 4 years ago

If it has to be in the class (like properties and methods), it will go into the parentheses. Otherwise it will stay outside (instances). ;-)

51783fa44783abd3b8000267_165551097 Sarah B about 4 years ago

This is correct boring12345

6e9943ca2933a1caf281e06d71762eca?s=140&d=retro Adamace over 3 years ago

tanx for the solution bro :D this help me eventhough its simple


2 votes

permalink

Here is the solution to part two of the exercise.
He uses $obj1 as a way to ad new instances(obj1 is just an example).
$teacher = new Person();

$student = new Person();

Remember you're creating instances for the person class. Took me a while because that obj1 threw me off, I was thinking necessary to use it. Sometimes the directions are a little screwy.

301 points
516de9ceb4ad23e17d0028f9_813111388
Submitted by
Miciah Martin
over 4 years ago


0 votes

permalink

<?php
class Classname {
}
$teacher = new Classname();
$student = new Classname();
?> not working

407 points
528e510080ff3303b0000d2b_550164241
Submitted by
treywhite713
over 3 years ago

1 Comment

6e9943ca2933a1caf281e06d71762eca?s=140&d=retro Adamace over 3 years ago

just follow the instruction your class must be named a "Person" in order to work your code bro :D


0 votes

permalink

I had this thing right, but it gave me the error: "Have you added the php tags?" I had, but I wrote it on line 10 instead of line 9...

916 points
Picture
Submitted by
Asbjørn Sørensen
over 3 years ago

1 Comment

6e9943ca2933a1caf281e06d71762eca?s=140&d=retro Adamace over 3 years ago

maybe u dont have a closing tags for that bro :D