3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Books{ /* Member variables */ public $price; public $title; /* Member functions */ public function setPrice($par){ $this->price = $par; } public function getPrice(){ echo $this->price.'<br/>'; } public function setTitle($par){ $this->title = $par; } public function getTitle(){ echo $this->title.'<br/>'; } public function __construct($par1 = '',$par2 = ''){ $this->title = $par1; $this->price = $par2; } } class Novel extends Books { public $publisher; public function setPublisher($par){ $this->publisher = $par; } public function getPublisher(){ echo $this->publisher; } } $physics = new Books("Physics for High School" , 2000); $chemistry = new Books("Advanced Chemistry" , 1200); $maths = new Books("Algebra", 3400); $physics->getTitle(); $chemistry->getTitle(); $maths->getTitle(); $physics->getPrice(); $chemistry->getPrice(); $maths->getPrice(); if (class_exists('Novel')) { echo 'yes'; } $pN = new Novel(); $pN->setPublisher("Barnes and Noble"); $pN->getPublisher();
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 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, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Physics for High School<br/>Advanced Chemistry<br/>Algebra<br/>2000<br/>1200<br/>3400<br/>yesBarnes and Noble
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Physics for High School<br/>Advanced Chemistry<br/>Algebra<br/>2000<br/>1200<br/>3400<br/>yesBarnes and Noble

preferences:
253.27 ms | 402 KiB | 287 Q