3v4l.org

run code in 300+ PHP versions simultaneously
<?php class String { protected $_string; public function __construct($string) { if(is_string($string)) $this->_string = $string; elseif(is_int($string)) $this->_string = $this->intToAscii($string); else $this->_string = null; echo('Error, string::__construct() argument 1 must be a string!'); } public function __toString() { return $this->_string; } public function ascii() { $code = ''; if(strlen($this->_string)==1) return ord($this->_string); else for($i = 0; $i < strlen($this->_string); $i++) { $code .= ord($this->_string[$i]); } return $code; } } $str = new String('Hello World!'); echo($str->ascii().' '); echo($str);
Output for 7.0.0
Fatal error: Cannot use 'String' as class name as it is reserved in /in/lqel7 on line 2
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Error, string::__construct() argument 1 must be a string!72101108108111328711111410810033 Hello World!

preferences:
170.85 ms | 1395 KiB | 35 Q