PHP lab

Run Settings
LanguagePHP
Language Version
Run Command
<?php include "./dio.php"; use main\classes\Recipe; $recipe1 = new Recipe(); echo $recipe1->source; $recipe1->source = "Grandma Holligan"; echo $recipe1->source; $recipe1->setTitle("My first recipe"); $recipe1->getTitle(); $recipe1->addIngredient("egg", 1); $recipe1->addIngredient("flour", 2, "cup"); $recipe2 = new Recipe(); $recipe2->source = "Betty Crocker"; $recipe1->setTitle = "My second recipe"; echo $recipe1->source; echo $recipe2->source; echo $recipe1->displayRecipe(); echo $recipe2->displayRecipe(); foreach ($recipe1->getIngredients() as $ing) { echo "\n" . $ing["amount"] . " " . $ing["measure"] . " " . $ing["item"]; } // var_dump($recipe1);
<?php namespace main\classes; class Recipe { private $title; public $ingredients = array(); public $instruction = array(); public $yield; public $tag = array(); public $source = 'Alena Holligan'; private $measurements = array( "tsp", "tbsp", "cup", "oz", "lb", "fl oz", "pint", "quart", "gallon" ); public function displayRecipe() { return $this->title . "by" . $this->source; } public function addIngredient($item, $amount=null, $measure=null) { if ($amount != null && !is_float($amount) && !is_int($amount)) { exit("The amount must be a float: " . gettype($amount) . $amount . "given"); } if ($measure != null && !in_array(strtolower($measure), $this->measurements)) { exit("Please enter a valid measurement: " . implode(", ", $this->measurements)); } $this->ingredients[] = array ( "item" => ucwords($item), "amount" => $amount, "measure" => strtolower($measure) ); } public function getIngredients() { return $this->ingredients; } public function setTitle($title) { $this->title = ucwords($title); } public function getTitle() { return $this->title; } }
<?php namespace main\struct; // trait is like mixin in Vue trait Mixin { } class Video { private $name; private $link; public function __construct(string $name) { $this->name = $name; } public function setLink(string $link){ $this->link = $link; } } class Example { public function __construct($title = null) { $this->setTitle($title); } public function __toString() { $output = "You are calling a " . __CLASS__ . " object with the title \""; $output .= $this->getTitle() . "\""; $output .= "\nIt is stored in " . basename(__FILE__) . " at " . __DIR__ . "."; $output .= "\nThis display is from line " . __LINE__ . " in method " . __METHOD__; $output .= "\nThe following methods are available for objects of this class: \n"; $output .= implode("\n", get_class_methods(__CLASS__)); return $output; } } class Render { public function __toString() { $output = "The following methods are available for " . __CLASS__ . " objects: \n"; $output .= implode("\n", get_class_methods(__CLASS__)); return $output; } } class Fish { public $common_name; public $flavor; public $record_weight; public function __construct($name, $flavor, $record) { $this->common_name = $name; $this->flavor = $flavor; $this->record_weight = $record; } public function getInfo() { return "A {$this->common_name} is an {$this->flavor} flavored fish. The world record weight is {$this->record_weight}."; } }
Editor Settings
Theme
Key bindings
Full width
Lines