Hello Sir/Madam,
One thing doesn’t works for me in PHP about printing the full name using the class method User.
I did this
$record = User::find_by_id(1);
$user = new User();
$user->id = $record['id'];
$user->username = $record['username'];
$user->password = $record['password'];
$user->first_name = $record['first_name'];
$user->last_name = $record['last_name'];
echo 'First name is :' . $user->first_name;
echo '<br />Last name is :' . $user->last_name;
echo '<br />Full name is :' . $user->full_name();
I got the output as following:
First name is :Mohan
Last name is :Sinfh
Full name is :Empty
Full name is empty.
How it could be possible?
the method in User class I wrote is,
class User {
public $id;
public $username;
public $password;
public $first_name;
public $last_name;
public function full_name(){
if(isset($this->$first_name) && isset($this->last_name)) {
return $this->$first_name . ' ' . $this->$last_name;
}
else {return "Empty";}
}
}
Thanks.