3v4l.org

run code in 300+ PHP versions simultaneously
<?php // a single colon indicates the option takes a value // a double colon indicates the value may be omitted $shortopts = "hf:v::d"; // GNU-style long options are not required $longopts = ["help", "version"]; $opts = getopt($shortopts, $longopts); // options without values are assigned a value of boolean false // you must check their existence, not their truthiness if (isset($opts["h"]) || isset($opts["help"])) { fprintf(STDERR, "Here is some help!\n"); exit; } // long options are called with two hyphens: "--version" if (isset($opts["version"])) { fprintf(STDERR, "%s Version 223.45" . PHP_EOL, $argv[0]); exit; } // options with values can be called like "-f foo", "-ffoo", or "-f=foo" $file = ""; if (isset($opts["f"])) { $file = $opts["f"]; } if (empty($file)) { fprintf(STDERR, "We wanted a file!" . PHP_EOL); exit(1); } fprintf(STDOUT, "File is %s" . PHP_EOL, $file); // options with optional values must be called like "-v5" or "-v=5" $verbosity = 0; if (isset($opts["v"])) { $verbosity = ($opts["v"] === false) ? 1 : (int)$opts["v"]; } fprintf(STDOUT, "Verbosity is %d" . PHP_EOL, $verbosity); // options called multiple times are passed as an array $debug = 0; if (isset($opts["d"])) { $debug = is_array($opts["d"]) ? count($opts["d"]) : 1; } fprintf(STDOUT, "Debug is %d" . PHP_EOL, $debug); // there is no automated w
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined variable $shortopts in /in/Vq0H2 on line 6 Deprecated: getopt(): Passing null to parameter #1 ($short_options) of type string is deprecated in /in/Vq0H2 on line 6 We wanted a file!
Process exited with code 1.
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 Warning: Undefined variable $shortopts in /in/Vq0H2 on line 6 Deprecated: getopt(): Passing null to parameter #1 ($short_options) of type string is deprecated in /in/Vq0H2 on line 6 We wanted a file!
Process exited with code 1.
Output for 8.0.0 - 8.0.30
Warning: Undefined variable $shortopts in /in/Vq0H2 on line 6 We wanted a file!
Process exited with code 1.
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined variable: shortopts in /in/Vq0H2 on line 6 We wanted a file!
Process exited with code 1.
Output for 7.3.32, 7.4.26
We wanted a file!
Process exited with code 1.

preferences:
136.62 ms | 401 KiB | 179 Q