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

Objects in PHP Forum

View Course » View Exercise

87 points
Picture
Submitted by
Greig Strafford
over 3 years ago

4/10 Passed but issue with $isAlive

Kept on failing the code even though everything checked out,
Ended up having to use $isAlive as a property but when calling echo $teacher-> I had to use ->isalive (lower case 'a' instead of 'A'). Is this standard? It was frustrating not being able to understand why it was failing, I tried $isalive but this threw the "do you have a $isAlive" error..

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

7 votes

permalink

Using quotes on your true is killing the boolean data type magic.

3698 points
55df2afa95e3787b9200005e_359368177
Submitted by
Judy
over 3 years ago

1 Comment

919ddc943ca721fa46eca5228ea37ee3?s=140&d=retro Ignacio over 3 years ago

a little hack

echo $teacher->isAlive."";

3 votes

permalink

the quotes on true breaks the boolean, and your last line should be something like $teacher->isAlive;

564 points
598f7ca0dd1ede9c200002f3_482639924
Submitted by
Lilian Asteri
over 3 years ago


2 votes

permalink

I think your problem might be that you echo $teacher->isalive; and you should echo $teacher->isAlive;

1156 points
52a60039631fe96e88000040_45813265
Submitted by
Lauri Domski
over 3 years ago


1 vote

permalink

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

407 points
528e510080ff3303b0000d2b_550164241
Submitted by
treywhite713
over 3 years ago

5 Comments

55df2afa95e3787b9200005e_359368177 Judy over 3 years ago

@trey, this looks to be the exact code of the OP, did you try the solutions that have been offered?

528e510080ff3303b0000d2b_550164241 treywhite713 over 3 years ago

yes

55df2afa95e3787b9200005e_359368177 Judy over 3 years ago

@treywhite713, it would be helpful if you showed us your code that has the changes in it then.

4f2752f2dbe69bc529f2e69060875239?s=140&d=retro wbutlern over 3 years ago

change the a in isalive to an A like you wrote it in beginning !!! ;) ---> echo $teacher->isAlive;

5327d37e631fe94f6a001bb5_565716449 JaneO over 3 years ago

Take quotes away from true. Booleans don't get quotes!


0 votes

permalink

I had the same problem. I'm thinking that when it is checked, we need to use the exact code the exercise writer used to pass

1273 points
Picture
Submitted by
Peter D Fisher
over 3 years ago


0 votes

permalink

The problem that I was having is that the output box shows "Fatal error: 'Teacher' not found on line 16", and I couldn't figure out what was wrong with this code!
<?php
class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
}
$teacher = new Teacher(); //line 16
$student = new Student();
echo $teacher->isAlive;
?>
However, If you just Save & Submit Code, ignoring the output box, it appears to be correct.

65 points
52f21815548c3596bf0007dd_774264107
Submitted by
Phillip
over 3 years ago

2 Comments

2aadc11ac893f08c87845e3671db6a8b?s=140&d=retro Jalen Davenport over 3 years ago

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

2aadc11ac893f08c87845e3671db6a8b?s=140&d=retro Jalen Davenport over 3 years ago

In your code, Person, Teacher, and Student need to have the same name...


0 votes

permalink

Believe it or not, the output give the number one. In Binary, that would be true. Here's what I wrote:
<?php
class Person {
public $isAlive = true;
public $firstname, $lastname, $age;
}
$teacher = new Person();
echo $teacher->isAlive;
$student = new Person();

    ?>

1366 points
54d5229be39efeb028002fb1_48708903
Submitted by
Mark Dunn
about 2 years ago