php - I have define a class and instantiate it and after that I am calling methods of this class but it is not giving any output? -
code here: $obj instance of class user.i calling methods not showing output
<?php class user{ public $name; public $age; public function _ _construct($name, $age){ $this->name=$name; $this->age=$age; } public function sayhello(){ echo("hiiiii".$this->name."!!!"); } public function sayage(){ $a=time()-strtotime($this->age); echo " hello age is".floor($a/(365*30*60*60)); } } $obj = new user('xyz','16 july 1980'); $obj->sayhello(); $obj->sayage(); ?>
just remove $var
$obj.
call $obj
<?php class user{ public $name; public $age; public function __construct($name, $age){ $this->name=$name; $this->age=$age; } public function sayhello(){ echo("hiiiii".$this->name."!!!"); } public function sayage(){ $a=time()-strtotime($this->age); echo " hello age is".floor($a/(365*30*60*60)); } } $obj = new user('xyz','16 july 1980'); $obj->sayhello(); $obj->sayage(); ?>
Comments
Post a Comment