У меня есть следующий класс, который имеет много закрытых переменных.
class plantOfTheMonth {
//Declare which centre(s) are being used
private $centre = "";
//Declare the attributes of the current Plant Of The Month
private $name = "";
private $latinName = "";
private $image = "";
private $imageAlt = "";
private $imageLink = "";
private $strapLine = "";
private $description = "";
private $colour = "";
private $centres = "";
//Declare variables for error handling
private $issue = "";
private $issueCode = "";
public function __construct() {
}
public function returnAttributes() {
$list = ""; //Set an Empty List
foreach($this as $key => $value) {
decodeText($value); //decode performs a stripslashes()
$$key = $value; //Use a variable variable and assign a value to it
$list .= "'".$key."', "; //add it to the list for the compress()
}
$list .= substr($list, 0, -2); //Take the final ", " off
return compact($list); //return the list of variables as an array
}
}
Я хочу вернуть все атрибуты как переменные со своими значениями, чтобы я мог предварительно заполнить поле формы,У меня есть запрос к базе данных, который заполняет все атрибуты (что доказано тестированием).В мои дни до OO я извлекал информацию из базы данных, помещал ее в переменные, затем использовал compress () для отправки и extract () для получения всех переменных.Это то, что будет работать, как в методе returnAttributes () в моем классе?