3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace Iterators\Classes; class FizzBuzz implements \Iterator { protected $pointer = 0; protected $numbers = []; public function __construct($numbers=[]) { $this->numbers = $numbers; return; } public function current() { $returnValue = ''; $returnValue .= ($this->numbers[$this->pointer]%3===0?'Fizz':''); $returnValue .= ($this->numbers[$this->pointer]%5===0?'Buzz':''); $returnValue = (empty($returnValue)?$this->numbers[$this->pointer]:$returnValue); return $returnValue; } public function key() { return $this->pointer; } public function next() { $this->pointer++; return; } public function rewind() { $this->pointer=0; return; } public function valid() { return isset($this->numbers[$this->pointer]); } }; $fizz = new FizzBuzz(15); echo $fizz->current(); echo $fizz->key(); echo $fizz->next(); echo $fizz-rewind();
based on EjjPP
Output for 5.4.0 - 7.2.0
FizzBuzz0 Warning: rewind() expects exactly 1 parameter, 0 given in /in/ecRel on line 47 Notice: Object of class Iterators\Classes\FizzBuzz could not be converted to int in /in/ecRel on line 47 1
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/ecRel on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/ecRel on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/ecRel on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ecRel on line 3
Process exited with code 255.