I can not figure out what is going wrong but on this simple PHP below, I am getting parse errors.
I am getting this error
Parse error: syntax error, unexpected T_STRING in E:\Server\htdocs\myframework\library\api\rest-test\index.php on line 3
on this code
<?php
header('HTTP/1.1 404 Not Found');
header('Content-type: application/json');
$data = 'testing dgdg dfgdf gdf';// my code that returns the appropriate data;
echo json_encode($data);
?>
However when I swap out header('HTTP/1.1 404 Not Found'); for header('HTTP/1.1 200 OK'); then the error goes away. Please help me understand this. Testing on Windows with XAMPP
RESOLVED
My original code had a blank space at the end of the header('HTTP/1.1 404 Not Found'); line, removed that space and everything works as expected now.
First, you should consider using
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");instead ofheader('HTTP/1.1 404 Not Found');owing to the fact that your underlying server might be using different HTTP Protocols and this will keep you from having to update it later.Second, I suspect the issue is stemming from the Content Header you are adding to the section. Try removing
header('Content-type: application/json');and see if it resolves your issue.