3v4l.org

run code in 300+ PHP versions simultaneously
<?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' => null, 'measures' => [], ]; public function hydrate(PDO $dbh, int $id): void { $stmt = $dbh->prepare("SELECT `title`, `latin_title`, `category`, `calories`, `proteins`, `fats`, `carbohydrates`, `description`, `measures`, `tags` FROM `cook_encyclopedia_entries` WHERE `id`=:id"); $result = $stmt->execute($id); $this->data = $result->fetch(PDO::FETCH_ASSOC); $this->data['measures'] = $this->computeMeasures($this->data['measures']); $this->hydrated = true; } public function getData(): array { if (!$this->hydrated) { throw new \Exception('hydrate first'); } return $this->data; } private function computeMeasures(string $measures): array { $measureArray = explode('|', $measures); return [ 'g_in_tsp' => $measureArray[0], 'g_in_tbsp' => $measureArray[1], 'g_in_glass' => $measureArray[2], 'g_in_cup' => $measureArray[3], ]; } }
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
61.47 ms | 401 KiB | 8 Q