3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyClass { public $prop1 = "I'm a class property!"; public function setProperty($newval) { $this->prop1 = $newval; } public function getProperty() { return $this->prop1 . "<br/>"; } } $obj = new MyClass;// Class instantiation. //var_dump($obj); echo "1st drill:"."<br>"; echo $obj->getProperty(); //echo prop1 string (// Get the property value). $obj->setProperty('I am a new property value'."<br><br>"); echo $obj->getProperty(); // Read it out again to show the change. //Second Drill echo "second drill: "."<br>"; class class2 { public $obj2="I am the first variable from the second drill."; public function setProperty2($newval2) { $this->obj2=$newval2; } public function getProperty2($newval2) { return $this->obj2."<br>"; } } // Create two objects $obj = new MyClass; $obj2 = new class2; // Get the value of $prop1 from both objects echo $obj->getProperty(); //taken from first drill. echo $obj2->getProperty2(); // Set new values for both objects $obj->setProperty("I'm a new property value!"); $obj2->setProperty2("I belong to the second instance!"."<br><br>"); // Output both objects' $prop1 value echo $obj->getProperty(); echo $obj2->getProperty2();
Output for 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.6
1st drill:<br>I'm a class property!<br/>I am a new property value<br><br><br/>second drill: <br>I'm a class property!<br/> Fatal error: Uncaught ArgumentCountError: Too few arguments to function class2::getProperty2(), 0 passed in /in/k390G on line 42 and exactly 1 expected in /in/k390G:31 Stack trace: #0 /in/k390G(42): class2->getProperty2() #1 {main} thrown in /in/k390G on line 31
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20
1st drill:<br>I'm a class property!<br/>I am a new property value<br><br><br/>second drill: <br>I'm a class property!<br/> Warning: Missing argument 1 for class2::getProperty2(), called in /in/k390G on line 42 and defined in /in/k390G on line 31 I am the first variable from the second drill.<br>I'm a new property value!<br/> Warning: Missing argument 1 for class2::getProperty2(), called in /in/k390G on line 50 and defined in /in/k390G on line 31 I belong to the second instance!<br><br><br>

preferences:
197.65 ms | 403 KiB | 213 Q