How can I turn the data from a class method into the properties of that class? Is it possible?
For instance, the article
below class only has one property - $var1,
class article
{
public $var1 = "var 1";
public function __construct()
{
}
public function getRow()
{
$array = array(
"article_id" => 1,
"url" => "home",
"title" => "Home",
"content" => "bla bla"
);
return (object)$array;
}
}
To get $this properties,
$article = new article();
print_r($article->var1); // var 1
To get $this method,
$row = $article->getRow();
To get $this method's data,
print_r($row->title); // Home
It works fine in that way, but how if I want to make/ move this dat**a below to the **class's properties,
"article_id" => 1,
"url" => "home",
"title" => "Home",
"content" => "bla bla"
So I can just call the data like this,
$article = new article();
print_r($article->title); // Home
Is it possible?