httpful icon indicating copy to clipboard operation
httpful copied to clipboard

JsonHandler constructor arguments ambiguously defined

Open quixand opened this issue 11 years ago • 2 comments

It looks like at least one person is struggling with the JSON parser option (http://stackoverflow.com/questions/20079631/how-to-get-an-array-instead-of-object-when-requesting-json-data-using-httpful). Though they could have looked into the source a little better, its apparent that the generic $args variable is hiding the capability of the flag when documentation is automatically generated (http://phphttpclient.com/docs/class-Httpful.Handlers.JsonHandler.html). I would suggest that perhaps the init function be updated to a specific variable

public function init($decode_as_array = false) { $this->decode_as_array = $decode_as_array; }

There seems no reason to be passing an array to this class when it only has one argument.

quixand avatar Oct 15 '14 12:10 quixand

Agree that it could (and should) be clearer how to get an array instead of an object. The main reason this is an array is to keep a consistent method signature for init. JsonHandler extends MimeHandlerAdapter and we need the method signatures to stay consistent. I'll probably vote to start with better documentation for now. In hindsight, I wish that the default behavior for JH would have been an associative array all along as that seems to be a common hang up.

nategood avatar Oct 21 '14 19:10 nategood

And maybe you could add JSON_BIGINT_AS_STRING as an option as well. Very much needed for some api's where an id could be something like this 1234567890123456 (xboxapi.com in my case).

Edit: fixed it and issued a pull request (#189) to dev branch

IzaacJ avatar Jul 08 '15 07:07 IzaacJ