@ 2019-05-11T11:43:06Z <?php
namespace Cookpedia;
class Entry {
private $hydrated = false;
private $data = [
'id' => 0,
'title' => null,
'latin_title' => null,
'category' => 0,
'calories' => 0,
'proteins' => 0,
'fats' => 0,
'carbohydrates' => 0,
'description' => null,
'tags' => [],
'measures' => [],
];
public function hydrate(): Entity
{
return new Entity(...array_values($this->data));
}
}
class Entity
{
public function __construct(int $id, ?string $title, ?string $latinTitle, int $category,
int $calories, int $proteins, int $fats, int $carbohydrates, ?string $description,
array $tags, array $measures)
{
$this->carbohydrates = $carbohydrates;
}
}
$entity = (new Entry())->hydrate();
var_dump($entity);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Deprecated: Creation of dynamic property Cookpedia\Entity::$carbohydrates is deprecated in /in/YCYLP on line 34
object(Cookpedia\Entity)#2 (1) {
["carbohydrates"]=>
int(0)
}
Output for 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 object(Cookpedia\Entity)#2 (1) {
["carbohydrates"]=>
int(0)
}
preferences:dark mode live preview
201.37 ms | 403 KiB | 212 Q