PHP 7 has a new feature which is a return type declaration.
We can return type a 'string' like:
function myFunction ($a) : string { }
We can also return type an 'array' like:
function myFunction ($a) : array { }
But how can we declare a 'JSON' type of response?
JSON isn't a native datatype in PHP, it's a structured string. So if your function returns JSON, you're returning a string.
So function myFunction ($a) : string { }
would be correct.
If you want to describe the return further you should be using docs.
/**
* @return string $jsonString The returned string contains JSON
*/
function myFunction ($a) : string { }
The same also goes for serialized objects in PHP. A serialized object is a structured 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