Excuse me I'm new to PHP and I'm only doing tests so I do not know why this error is generated:
Notice: Undefined variable: firstName in C: \ xampp \ htdocs \ Programming \ PHP \ prueba.php on line 8
Notice: Undefined property: person :: $ in C: \ xampp \ htdocs \ Programming \ PHP \ prueba.php on line 8
Notice: Undefined variable: lastName in C: \ xampp \ htdocs \ Programming \ PHP \ prueba.php on line 8
Notice: Undefined property: person :: $ in C: \ xampp \ htdocs \ Programming \ PHP \ prueba.php on line 8
<?php
class person{
var $firstName=null;
var $lastName=null;
function fullname(){
return $this->$firstName . ' ' . $this->$lastName;
}
}
$person1 = new person;
$person1->firstName = 'Samuel';
$person1->lastName = 'Vieyra';
exit($person1->fullname());
?>
Update1
<?php
class person{
var $firstName=null;
var $lastName=null;
function fullname(){
return $this->$firstName . ' ' . $this->$lastName;
}
}
$person1 = new person();
$person1->firstName = 'Samuel';
$person1->lastName = 'Vieyra';
exit($person1->fullname());
?>