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

Objects in PHP Forum

View Course » View Exercise

922 points
52983e67abf821c6b5005d7f_23743677
Submitted by
Jane Cui
almost 3 years ago

Why does this code print out "1" instead of "true"?

Code:

<?php

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


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

echo $teacher->isAlive;


?>

4 votes

permalink

in all the programming languages True = 1 , False =0 (based on the Binary)
so if you print true it's gonna output ->1

112 points
531111af80ff33d67900044a_938633085
Submitted by
Mohamed Algendy
almost 3 years ago


3 votes

permalink

in PHP the boolean true is represented by 1 and false by space. Cheers

365 points
543fc82f631fe988640020d7_382532424
Submitted by
Tobias Páez
almost 3 years ago

1 Comment

219ab7f772efb1cd5440659fe629340a?s=140&d=retro David Hollowood about 2 years ago

Thank you. I don't recall seeing that anywhere in the instructions though I might have missed it. I was guessing this was the case but it's nice to have it confirmed.