So, while documenting a php code I'm writing, I stopped where I usually said @return string The json output
, on functions that I actually returned json.
So, I was wondering if it is right to set
*
* @return json
*/
public function test()
{
$test = array('hola' => array('en' => 'hello', 'ro' => 'salut'));
return json_encode($test);
}
instead of
*
* @return string
*/
public function test()
{
$test = array('hola' => array('en' => 'hello', 'ro' => 'salut'));
return json_encode($test);
}
I searched for related question, and overlooked manuals, but non that I have seen, had mentioned my doubt.
http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.return.pkg.html
Just as a reference, of where I got all this started. I saw a couple of times, the following:
*
* @return View
*/
So, I guess that is a proper return?
json() The json() method of the Response interface takes a Response stream and reads it to completion. It returns a promise which resolves with the result of parsing the body text as JSON .
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).
json() returns a JSON object of the result (if the result was written in JSON format, if not it raises an error). Python requests are generally used to fetch the content from a particular resource URI.
As orangepill commented, you should use the type string
and add JSON
in the description.
@return string JSON
PHPDoc Manual
@return datatype description
@return datatype1|datatype2 description
In reference to the datatype, the manual states
The datatype should be a valid PHP type (int, string, bool, etc), a class name for the type of object returned, or simply "mixed". If you want to explicitly show multiple possible return types, list them pipe-delimited without spaces (e.g. "@return int|string")
"json
" is not a primitive type in PHP, or in fact any type. You need to document returned types, not what the content of these types mean. If you specify json
as return "type", this implies an object of class json
, because json
has no other meaning in PHP.
You can only document it as returning a string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With