code is here: $obj is the instance of class user.I am calling methods it is not showing the 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 Your age is".floor($a/(365*30*60*60));
}
}
$obj = new user('xyz','16 july 1980');
$obj->sayHello();
$obj->sayAge();
?>
Just remove $var
from $obj.
Call it as just $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 Your age is".floor($a/(365*30*60*60));
}
}
$obj = new user('xyz','16 july 1980');
$obj->sayHello();
$obj->sayAge();
?>
It's because you have a syntax error on this line, and it's likely you aren't showing debugging/error messages in your PHP configuration so it looks like nothing is showing up:
var $obj = new user('xyz','16 july 1980');
"var" in front of that variable is not valid PHP syntax.
your contruct method is wrong
public function _ _construct($name, $age){
$this->name=$name;
$this->age=$age;
}
remove the space and it should work
also remove the var from $obj