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

Objects in PHP Forum

View Course

692 points
55f6bbb9937676b0aa00059e_129087668?awsaccesskeyid=akiajkz7qvqfd72xnj3q&expires=1508624452&signature=xao1vbjx10dejbpzickrb1xshq0%3d
Submitted by
Darkhorse
about 2 years ago

Stuck on 6/10. Anyone got the whole code?

Stuck on 6/10. Explanation and hints not helpful for this and the previous lesson. Anyone got the whole code? This part of the course is not geared for beginner programmers.


1 vote

permalink

I hope this helps you.
This is my code:

<!DOCTYPE html>
<html>
<head>
   <title>Reconstructing the Person Class</title>
  <link type='text/css' rel='stylesheet' href='style.css'/>
 </head>
<body>
  <p>
<!-- Your code here -->
<?php
class Person {
    public $isAlive = true;
    public $firstname;
    public $lastname;
    public $age;
    public function __construct($firstname, $lastname, $age) {
        $this->firstname = $firstname;
        $this->lastname = $lastname;
        $this->age = $age;
    }
    public function greet() {
        return "Hello, my name is".$this->firstname." ".$this->lastname."                          .Nice to meet you! :-)";
    }

}
$teacher = new Person(" boring", " 12345 ", 12345);
$student = new Person(" Bobbi ", "Cruz ", 20);

echo $teacher->greet();
echo $student->greet();


?>
</p>
 </body>

 </html>

It worked for me.

1629 points
56536b35d3292f456400061f_537268122
Submitted by
Queen Fiona Fox
about 2 years ago


0 votes

permalink

Hi,
Thanks for that. I left all the earlier stuff in as well and passed. Here's mine.

<?php
class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function__construct($firstname, $lastname, $age) {
}
public function greet("Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)" ){

    }
    $teacher = new Person("boring", "12345", 12345);
    $student = new Person("Fred","Bloggs", 42);

    echo $teacher->isAlive;
    echo $student->age;
    echo $teacher->greet;
    echo $student->greet;
    ?> 
  </p>

432 points
563f564eb62548d5c9000854_286301216
Submitted by
Darkhorse2
about 2 years ago