Re: Return type declaration and &return.falseforfailure;
| From: | Richard Quadling | Date: | Sun, 11 Feb 2018 22:56:10 +0000 |
| Subject: | Re: Return type declaration and &return.falseforfailure; | ||
| References: | 1 2 3 4 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969386884@lists.php.net to get a copy of this message | ||
We should be adding <void> if there is no return value. If a function can
return null, then that's a valid return type. The issue here is that many
of the PHP functions return way too many types.
The inability of the function/method signature correctly express itself is
a pain. You read the signature. It says "I return stuff". I then have to
read the rest of the documentation to find that it returns something useful
or false.
<type>int</type><type>false</type> (as true and false are now types), is
very explicit, understandable, parseable and can be used by other systems
in a concise way.
And don't get me started on the fact the structure of the signature is not
PHP compliant!
mixed function(type param)
is not correct.
function(type param): mixed
is what it should be.
For a newbie reading the PHP dox for the first time and seeing the wrong
structure, trying to use it, failing, ...
On 11 February 2018 at 22:19, Christoph M. Becker <cmbecker69@gmx.de> wrote:
> On 11.02.2018 at 22:31, Richard Quadling wrote:
>
> > DocBook 5.2 now supports multiple types, so, really, the form
> SHOULD/COULD
> > be
> >
> > <type>int</type><type>bool</type>
> >
> > In my opinion, <type>mixed</type> is lazy. We now have scalar type
> hinting
> > (though not union type hints which is a shame as that matches the
> language
> > itself quite a lot).
> >
> > If the documentation can be accurate, then it should be.
>
> Well, then we'd have to add NULL as return type to almost every
> function. IMHO, not really helpful.
>
> > On 5 December 2017 at 10:15, Andrew Gromov <andrewgrom@rambler.ru>
> wrote:
> >
> >> I see many changes from anonymous users like this:
> >>
> >> - <type>int</type><methodname>preg_match</methodname>
> >> + <type>int|bool</type><methodname>preg_match</methodname>
> >>
> >>
> >> or this:
> >>
> >> - <type>int</type><methodname>preg_match_all</methodname>
> >> + <type>mixed</type><methodname>preg_match_all</methodname>
> >>
> >>
> >> Formally them correct, but by spirit them is bad (imho).
> >>
> >> Accept or reject them?
>
> --
> Christoph M. Becker
>
--
Richard Quadling