3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class String { protected $_string; public function __construct($string) { if(is_string($string)) $this->_string = $string; elseif(is_int($string)) $this->_string = chr($string); else 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);
based on PmMJq
Output for 7.0.0
Fatal error: Cannot use 'String' as class name as it is reserved in /in/TYeH0 on line 2
Process exited with code 255.
Output for 5.3.20 - 5.6.28
72101108108111328711111410810033 Hello World!