Is json allowed to return to documentation?

So, documenting the php code that I am writing, I stopped, where @return string The json output usually said, about the functions that I actually returned json.

So, I was wondering if it’s right to install

 * * @return json */ public function test() { $test = array('hola' => array('en' => 'hello', 'ro' => 'salut')); return json_encode($test); } 

instead

 * * @return string */ public function test() { $test = array('hola' => array('en' => 'hello', 'ro' => 'salut')); return json_encode($test); } 

I searched for the corresponding question and overlooked the guidelines, but did not see what I saw, mentioned my doubts.

http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.return.pkg.html

Update

As a link, where I started it all. I saw a couple of times the following:

 * * @return View */ 

So, I think this is the right comeback?

+4
source share
3 answers

" json " is not a primitive type in PHP or virtually any type. You need to document the returned types, not what the contents 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 write it as a return string .

+3
source

As orangepill commented, you should use the string type and add JSON to the description.

@return string JSON

PHPDoc Guide

 @return datatype description @return datatype1|datatype2 description 

For data type, the manual indicates

The data type must be a valid PHP type (int, string, bool, etc.), and the class name for the return type of the object or simply "mixed". if you want to explicitly show several possible return types, list them without restrictions (for example, "@return int | string")

+5
source

I would rather see the json return type. It is true that you are returning json as a string, however json is more defined and lets others know what to expect.

0
source

Source: https://habr.com/ru/post/1490755/


All Articles