3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Thesaurus { protected $synonyms = array( array('wonderful', 'great', 'amazing', 'fabulous', 'awesome', 'stunning'), array('look', 'see', 'observe') ); public function lookup($word) { foreach ($this->synonyms as $index => $synonym) { if (in_array(strtolower($word), $synonym)) { unset($synonym[$word]; return $synonym[ array_rand($synonym) ]; } } return $word; } } class Transformer { protected $thesaurus; public function __construct(Thesaurus $thesaurus) { $this->thesaurus = $thesaurus; } public function transform($string) { foreach (str_word_count($string, 1) as $word) { $string = $this->replace($word, $this->thesaurus->lookup($word), $string); } return $string; } private function replace($needle, $replacement, $haystack) { return preg_replace( '~' . preg_quote($needle, '~') . '~i', $replacement, $haystack, 1 ); } } $transformer = new Transformer(new Thesaurus); foreach (range(1, 20) as $index) { echo $transformer->transform('This is my wonderful description. It really is wonderful. Look how wonderful it is.'), PHP_EOL; }
Output for 5.3.0 - 5.4.23
Parse error: syntax error, unexpected ';', expecting ',' or ')' in /in/00P3S on line 12
Process exited with code 255.