• Re: phpdoc: function return type

    From J.O. Aho@21:1/5 to Tommy on Thu Jul 14 19:04:29 2022
    On 14/07/2022 18.23, Tommy wrote:
    /**
     * @return int|exit
     */
    function err($message, $exitCode) {
        $int = fwrite(STDERR, $message);

        if (null !== $exitCode) {
    if(!is_null($exitCode)) {

            exit($exitCode);
        }

        return $int;
    }

    In your opinion, int|exit is good as a type for @return tag?

    No, as exit do not return anything and also it will break the execution
    here. you should write it in the description that the function will stop
    the execution if the $exitCode ain't null. Maybe you should test that
    the exitCode ain't 0, as it's normally an exit code for something that
    went well.

    Or it would be better int|null?

    No, the function will return int or false

    Or it would be better simply int?

    As you are returning the return value from fwrite(), then it's int or
    false.
    https://www.php.net/manual/en/function.fwrite.php


    --

    //Aho

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tommy@21:1/5 to All on Thu Jul 14 18:23:06 2022
    /**
    * @return int|exit
    */
    function err($message, $exitCode) {
    $int = fwrite(STDERR, $message);

    if (null !== $exitCode) {
    exit($exitCode);
    }

    return $int;
    }

    In your opinion, int|exit is good as a type for @return tag?
    Or it would be better int|null?
    Or it would be better simply int?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tommy@21:1/5 to All on Fri Jul 15 15:52:56 2022
    Il 14/07/22 19:04, J.O. Aho ha scritto:
    ...

    thanks

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)