3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo "Fourth drill:"."<br><br>"; class MyClass4 { public $prop1 = "I'm a class property!"; public function __construct() { echo 'The class "', __CLASS__, '" was initiated!<br />'; } public function __destruct() { echo 'The class "', __CLASS__, '" was destroyed.<br />'; } public function __toString() { echo "Using the toString method: "; return $this->getProperty(); } public function setProperty($newval) { $this->prop1 = $newval; } public function getProperty() { return $this->prop1 . "<br />"; } } class MyOtherClass extends MyClass4 { public function newMethod() { echo "From a new method in " . __CLASS__ . ".<br />"; } } // Create a new object $newobj = new MyOtherClass; // Output the object as a string echo $newobj->newMethod(); // Use a method from the parent class. echo $newobj->getProperty(); ?>
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 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.6
Fourth drill:<br><br>The class "MyClass4" was initiated!<br />From a new method in MyOtherClass.<br />I'm a class property!<br />The class "MyClass4" was destroyed.<br />

preferences:
146.75 ms | 404 KiB | 223 Q