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

Objects in PHP Forum

View Course » View Exercise

68 points
Fe95f1bee1de6931584edae2df7ddf3d?s=140&d=retro
Submitted by
Navin Samuel
over 3 years ago

I can't understand this given program. Please explain.

<!DOCTYPE html>


Introduction to Object-Oriented Programming




<?php
// The code below creates the class
class Person {
// Creating some properties (variables tied to an object)
public $isAlive = true;
public $firstname;
public $lastname;
public $age;

        // Assigning the values
        public function __construct($firstname, $lastname, $age) {
          $this->firstname = $firstname;
          $this->lastname = $lastname;
          $this->age = $age;
        }

        // Creating a method (function tied to an object)
        public function greet() {
          return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
        }
      }

    // Creating a new person called "boring 12345", who is 12345 years old ;-)
    $me = new Person('boring', '12345', 12345);

    // Printing out, what the greet method returns
    echo $me->greet(); 
    ?>
    </p>
</body>

0 votes

permalink

HI...i think that the error is in function greet(). Try to past and copy the return text that is in the exercise...maybe work

This is my exercise:
class Person {
// Creating some properties (variables tied to an object)
public $isAlive = true;
public $firstname;
public $lastname;
public $age;

        // Assigning the values
        public function __construct($firstname, $lastname, $age) {
          $this->firstname = $firstname;
          $this->lastname = $lastname;
          $this->age = $age;
        }

        // Creating a method (function tied to an object)
        public function greet() {
          return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
        }
      }

    // Creating a new person called "boring 12345", who is 12345 years old ;-)
    $me = new Person('boring', '12345', 12345);

    // Printing out, what the greet method returns
    echo $me->greet(); 
    ?>

526 points
053db5742e7524277680238d019772c8?s=140&d=retro
Submitted by
fede909
over 3 years ago

1 Comment

543fc82f631fe988640020d7_382532424 Tobias Páez about 3 years ago

Sorry Navim, What don't you understand?, Please be more detail in a way to explain you...