3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ColorCLI { static $foreground_colors = array( 'bold' => '1', 'dim' => '2', 'black' => '0;30', 'dark_gray' => '1;30', 'blue' => '0;34', 'light_blue' => '1;34', 'green' => '0;32', 'light_green' => '1;32', 'cyan' => '0;36', 'light_cyan' => '1;36', 'red' => '0;31', 'light_red' => '1;31', 'purple' => '0;35', 'light_purple' => '1;35', 'brown' => '0;33', 'yellow' => '1;33', 'light_gray' => '0;37', 'white' => '1;37', 'normal' => '0;39', ); static $background_colors = array( 'black' => '40', 'red' => '41', 'green' => '42', 'yellow' => '43', 'blue' => '44', 'magenta' => '45', 'cyan' => '46', 'light_gray' => '47', ); static $options = array( 'underline' => '4', 'blink' => '5', 'reverse' => '7', 'hidden' => '8', ); public static function __callStatic( $foreground_color, $args ) { $string = $args[0]; $colored_string = ""; // Check if given foreground color found if( isset(self::$foreground_colors[$foreground_color]) ) { $colored_string .= "\033[" . self::$foreground_colors[$foreground_color] . "m"; }else{ die( $foreground_color . ' not a valid color'); } array_shift($args); foreach( $args as $option ){ // Check if given background color found if(isset(self::$background_colors[$option])) { $colored_string .= "\033[" . self::$background_colors[$option] . "m"; }elseif(isset(self::$options[$option])) { $colored_string .= "\033[" . self::$options[$option] . "m"; } } // Add string and end coloring $colored_string .= $string . "\033[0m"; return $colored_string; } public static function bell($count = 1) { echo str_repeat("\007", $count); } } echo ColorCLI.red("text");
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.6
Fatal error: Uncaught Error: Undefined constant "ColorCLI" in /in/mA3kf:59 Stack trace: #0 {main} thrown in /in/mA3kf on line 59
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant ColorCLI - assumed 'ColorCLI' (this will throw an Error in a future version of PHP) in /in/mA3kf on line 59 Fatal error: Uncaught Error: Call to undefined function red() in /in/mA3kf:59 Stack trace: #0 {main} thrown in /in/mA3kf on line 59
Process exited with code 255.
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.33
Notice: Use of undefined constant ColorCLI - assumed 'ColorCLI' in /in/mA3kf on line 59 Fatal error: Uncaught Error: Call to undefined function red() in /in/mA3kf:59 Stack trace: #0 {main} thrown in /in/mA3kf on line 59
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Notice: Use of undefined constant ColorCLI - assumed 'ColorCLI' in /in/mA3kf on line 59 Fatal error: Call to undefined function red() in /in/mA3kf on line 59
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/mA3kf on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/mA3kf on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/mA3kf on line 5
Process exited with code 255.

preferences:
275.42 ms | 401 KiB | 448 Q