3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ErrorPrinter { /* String to print for an error where a parameter is missing from the post */ const ERROR_MISSING_PARAM = "10000"; private $errors = array(); private $number_of_errors = 0; function addError($error, $variable){ $this->errors[$variable] = $error; $this->number_of_errors = count($this->errors); } function printToJson(){ return json_encode($this->errors); } function getNumberOfErrors(){ return $this->number_of_errors; } } $printer = new ErrorPrinter; $printer->addError(ErrorPrinter::ERROR_MISSING_PARAM, 'name'); echo $printer->getNumberOfErrors . "\r\n"; echo $printer->printToJson();

preferences:
35.43 ms | 402 KiB | 5 Q