I have a class in php with a method similar to the two below. I am wondering what is the most optimal way to write this class? I need to use the disp_info method a lot and would like to know if it is wiser to place $message1 and $message2 outside of the function and call it in so I would not have to generate a new message every time or the other way around.
class Person(){
public $name;
public $age;
public $sex;
public $result;
public function disp_info(){
$message1= "Hello my name is : ";
$message2= "And my age is :";
$this->result= $message1.$this->name.$message2.$this->age;
}
$this->disp_name();
}
class Person(){
public $name;
public $age;
public $sex;
public $result;
public $message1= "Hello my name is : ";
public $message2= "And my age is :";
public function disp_info(){
$message1 = $this->message1
$message2 = $this->message2
$this->result = $message1.$this->name.$message2.$this->age;
}
$this->disp_name();
}
Thanks, Please enlighten me