Jump to content

Recommended Posts

How can i finish the following class to print "Person->name is only human" when the following is executed on a Person object: print $person;

 

class Person{

private $name = '';

 

public function __construct($name){

$this->name = $name;

}

}

$person = new Person('Andrew');

print $person; // Andrew is only human

 

Link to comment
https://forums.phpfreaks.com/topic/205399-adding-more-output-to-a-print/
Share on other sites

i am not getting ur question and also the purpose of doing this.. but try this..

 

class Person{
   public $name = '';

   public function __construct($name){
      $this->name = $name;
   }
}
$person = new Person('Andrew');
echo $person->name. " is only human";// Andrew is only human

you are not stuck there.. if a person can create a class then he/she should  be knowing about appending the text to a variable... right????????

 

So, instead of taking a code from here and putting it in your assignment.... try to learn it.....ofcourse only if you are looking to be a developer.. otherwise.. keep doing it.. get marks.. but not knowledge..

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.