I am building a custom data handler to save some precious bandwidth for my users. Problem is, I am trying to add an object on the fly, into an array.
It is not working as expected.
Any help would be appreciated
function getName() {
return "test";
}
class Parser {
private $results = [];
public function parseCalls($callArray){
for ($i=0; $i < count($callArray); $i++) {
switch($callArray[$i]->call){
case 'getName':
$results[] = (object) ['result' => getName()]; // this is where it fails.
break;
}
}
}
public function sendResult(){
echo json_encode($this->results);
}
}
$parser = new Parser();
if(isset($_POST["callArray"])){
// $_POST['callArray'] contains [{call: 'getName'}];
$callsArray = json_decode($_POST["callArray"]);
$parser->parseCalls($callsArray);
}
$parser->sendResult();
How do I make it that the results array contains something like this:
[{result: "test"}]
Thank you very much! :)
$resultswithin the function is not defined but I assume it is meant to be the private property of the class - ie:$this->results[]=...