3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Programmer { // Class Properties var $name; // Programmer's name var $experience; // How long has been programming var $lang; // Favorite Language var $education; // Highest degree earned // Class Constructor - function same name as the class function Programmer($name, $experience, $lang, $education) { $this->name=$name; $this->experience=$experience; $this->lang=$lang; $this->education=$education; } // Getter/Setter functions for all properties in the class function get_name() { return $this->name; } function set_name($newname) { $this->name = $newname; } function get_experience() { return $this->experience; } function set_experience($newexperience) { $this->experience = $newexperience; } function get_lang() { return $this->lang; } function set_lang($newlang) { $this->lang = $newlang; } function get_education() { return $this->education; } function set_education($neweducation) { $this->education = $neweducation; } // Utility data dump function function output() { echo "Programmer Name: ".$this->name."<br>"; echo $this->name." has ".$this->experience." years of programming experience.<br>"; echo $this->lang." is ".$this->name."'s favorite programming language.<br>"; echo $this->name." holds the degree: ".$this->education."<br><br>"; } } // Instantiating a programmer $paul = new Programmer('Paul Conrad',12,'C++','Bachelor of Science in Computer Science'); $paul->output(); // Oops, Paul has programmed alot longer than 12 year, really is 22 years $paul->set_experience(22); $paul->output();
Output for 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
Programmer Name: <br> has years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>Programmer Name: <br> has 22 years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>
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 Programmer Name: <br> has years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>Programmer Name: <br> has 22 years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Programmer has a deprecated constructor in /in/ktHNZ on line 2 Programmer Name: Paul Conrad<br>Paul Conrad has 12 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>Programmer Name: Paul Conrad<br>Paul Conrad has 22 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.3.32 - 7.3.33
Programmer Name: Paul Conrad<br>Paul Conrad has 12 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>Programmer Name: Paul Conrad<br>Paul Conrad has 22 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>

preferences:
171.53 ms | 403 KiB | 228 Q