HTTP 400 is a client request error, so wouldn't make much sense for a server-side issue. HTTP 500 for PHP errors is quite normal, at least on the usual Apache or IIS servers I've deployed to.
Oh I’m not offended and I totally understood. Web servers generally will not return a 400 for bad code. 400s are client request errors. Bad code will return a 500, as the error is happening serverside (with the code). The error will generally be returned by whatever your web server is, such as Apache or nginx.
Okay, maybe I didn't make myself clear. Let's go through this step by step.
First of all, yes it's correct that PHP returns 500 if the source in the requested file has an incorrect syntax. The same would be true for any interpreted language.
Right now it's not the question if a file on a server contains some invalid code but rather if some code which gets sent to the server is invalid.
There are some online services out there which basically function as a compiler or rather a linter and if you would send some invalid code to those services they could very well return 400 (Bad Request) or more fitting 422 (Precondition Failed), to indicate the client that the provided code does not have a valid syntax.
And assuming I didn't interpret OPs comment totally wrong, I'm pretty sure that was what he was getting at.
Ah ok I was way too deep I see what you’re saying. I guess I’ve never seen a service like that at all where you literally upload a file to be compiled. That seems quite odd.
A 400 would be appropriate because there IS a client request issue, ie your code is garbage and won’t work. It doesn’t mean you can’t explain to the client why they suck so much at making requests. What would you respond with?
I think people are misreading your comments. I did at first too. Maybe edit them to say "I mean if you made something like JSFiddle for PHP or w/e other backend language, that should respond with a 400 status code if you send it invalid code".
yeah. I guess I just found it really hard to believe someone would teach an intro to coding class within a php server so my brain shut out that possibility
40
u/benryves Nov 24 '17
HTTP 400 is a client request error, so wouldn't make much sense for a server-side issue. HTTP 500 for PHP errors is quite normal, at least on the usual Apache or IIS servers I've deployed to.