I have json
encode method, I use this to built an api to return json
data. It's work perfectly, but after I install Xampp
new version again this will display an error:
Note - This works perfectly on my previous xampp, this error came after i installed new xampp
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$myObj[$a]->id = $row["district_code"];
$myObj[$a]->name = $row["district_name"];
$myObj[$a]->type = 'District';
$a++;
}
$myJSON = json_encode($myObj);
echo $myJSON;
}
?>
Error:
Fatal error: Uncaught Error: Attempt to assign property "id" on null