<?php
/* String to print for an error where a parameter is missing from the post */
const ERROR_MISSING_PARAM = "10000";
$errors = array();
$number_of_errors = 0;
function addError($error, $variable){
$errors[$variable] = $error;
$number_of_errors = count($errors);
}
function printToJson(){
return json_encode($this->errors);
}
addError(ERROR_MISSING_PARAM, 'name');
echo $number_of_errors . "\r\n";
echo printToJson();
0
Fatal error: Uncaught Error: Using $this when not in object context in /in/Bu5a7:17
Stack trace:
#0 /in/Bu5a7(22): printToJson()
#1 {main}
thrown in /in/Bu5a7 on line 17
Process exited with code 255.