3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Product { /* Static Methos and Properties example */ public static $manufacturer = "Bart Taylor"; public $name = 'default_name'; public $price = 0; public $desc = 'default description'; function __construct($name, $price, $desc){ $this->name = $name; $this->price = $price; $this->desc = $desc; } public function getInfo(){ return "Product Name: ". $this->name; } public function getMaker(){ return self::$manufacturer; } } /* Part on Object Inheritance */ //SUB-CLASS class Soda extends Product { public $flavor; function __construct($name, $price, $desc, $flavor){ parent::__construct($name, $price, $desc); $this->favor = $flavor; } public function getInfo(){ return "Product Name: ". $this->name . "Flavor: ". $this->flavor; } } $shirt = new Product("Space Juice T-Shirt", 20, "Awesome Grey T-Shirt");
Output for 5.0.0 - 7.1.0
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Ga4JW on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Ga4JW on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/Ga4JW on line 7
Process exited with code 255.