Ranter
Join devRant
Do all the things like
				++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
				Sign Up
			Pipeless API
 
				From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
				Learn More
			Comments
		- 
				
				True. It's stupid, but luckily for this case there is a quick workaround:
 
 $_POST = json_decode(file_get_contents('php://input'), true);
 
 Hopefully you will never have to send files (aka multipart/form-data) with PUT requests. You will see fun there.
- 
				
				@CoffeeAndHate It's worth to mention that this will fail if the string is not valid JSON.
 
 Another workaround to check JSON:
 
 function isValidJSON($str) {
 json_decode($str);
 return json_last_error() == JSON_ERROR_NONE;
 }
 
 $json_params = file_get_contents("php://input");
 
 if (strlen($json_params) > 0 && isValidJSON($json_params))
 $decoded_params = json_decode($json_params);
- 
				
				@tracktraps Of course, you always have to check for errors and user input. But I just wanted to point the essence of that, without making the post too bulky.
 
 Not to mention that unicode support for json in php sucks a lot.
- 
				
				All these php rants are making me consider avoiding php and just learn django or flask.
- 
				
				@DVZ96 It sounds worse than it is. Simply use a framework, such as Laravel (I prefer ZF3). This takes away most of the inconsistencies with PHP.
- 
				
				 hitzoR2558y@tracktraps Some basic one, like Slim, should do and is better if you want to have full controll over your app. hitzoR2558y@tracktraps Some basic one, like Slim, should do and is better if you want to have full controll over your app.
- 
				
				meletisf528y@DVZ96 If you use Laravel everything will be fine. It's not that bad when you follow a set of rules.
- 
				
				
Related Rants








 Source: /r/ProgrammerHumor
Source: /r/ProgrammerHumor
So, apparently when you're POSTing to PHP with Content-Type: application/json the $_POST variable will not get populated because PHP is not ready to support JSON as input. Because 1999.
undefined
php
json