3v4l.org

run code in 300+ PHP versions simultaneously
<?php class person { var $name; // variable inside class = property function __construct($persons_name=null) { $this->name = $persons_name; } function set_name($new_name) { $this->name = $new_name; } function get_name() { // function inside class = method return $this->name; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> <?php include("class_lib.php"); ?> </head>` <body> <?php // Create object WITHOUT constructor by calling a method $SecurityEngineer = new person(); $SecurityEngineer->set_name("Debbie B"); echo "<br>Debbie's full name: " . $SecurityEngineer->get_name()."<br>"; // Create object WITH a constructor $WanEngineer = new person("Lisa L"); echo "Lisa's full name: " . $WanEngineer->get_name(); ?> </body> </html>
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: include(): open_basedir restriction in effect. File(class_lib.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/O3l8L on line 25 Warning: include(class_lib.php): Failed to open stream: Operation not permitted in /in/O3l8L on line 25 Warning: include(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L </body> </html>
Output for 8.0.13
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: include(class_lib.php): Failed to open stream: No such file or directory in /in/O3l8L on line 25 Warning: include(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L </body> </html>
Output for 5.1.3 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0, 7.3.32 - 7.3.33, 7.4.33
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: include(class_lib.php): failed to open stream: No such file or directory in /in/O3l8L on line 25 Warning: include(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L </body> </html>
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.32
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: include(): open_basedir restriction in effect. File(class_lib.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/O3l8L on line 25 Warning: include(class_lib.php): failed to open stream: Operation not permitted in /in/O3l8L on line 25 Warning: include(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L </body> </html>
Output for 7.1.20, 7.2.6
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: include(): open_basedir restriction in effect. File(class_lib.php) is not within the allowed path(s): (/tmp:/in) in /in/O3l8L on line 25 Warning: include(class_lib.php): failed to open stream: Operation not permitted in /in/O3l8L on line 25 Warning: include(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L </body> </html>
Output for 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/O3l8L on line 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: include(class_lib.php): failed to open stream: No such file or directory in /in/O3l8L on line 25 Warning: include(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L </body> </html>
Output for 5.0.0 - 5.0.5
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/O3l8L on line 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: main(class_lib.php): failed to open stream: No such file or directory in /in/O3l8L on line 25 Warning: main(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L </body> </html>
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: main(class_lib.php): failed to open stream: No such file or directory in /in/O3l8L on line 25 Warning: main(): Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: </body> </html>
Output for 4.3.0 - 4.3.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta> <title>Learning OOP Constructor </title> Warning: main(class_lib.php) [http://www.php.net/function.main]: failed to create stream: No such file or directory in /in/O3l8L on line 25 Warning: main() [http://www.php.net/function.main]: Failed opening 'class_lib.php' for inclusion (include_path='.:') in /in/O3l8L on line 25 </head>` <body> <br>Debbie's full name: Debbie B<br>Lisa's full name: </body> </html>

preferences:
223.23 ms | 402 KiB | 313 Q