Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #19062 > unrolled thread
| Started by | Tommy <ba@ve.net> |
|---|---|
| First post | 2022-07-14 18:23 +0200 |
| Last post | 2022-07-15 15:52 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.php
phpdoc: function return type Tommy <ba@ve.net> - 2022-07-14 18:23 +0200
Re: phpdoc: function return type "J.O. Aho" <user@example.net> - 2022-07-14 19:04 +0200
Re: phpdoc: function return type Tommy <ba@ve.net> - 2022-07-15 15:52 +0200
| From | Tommy <ba@ve.net> |
|---|---|
| Date | 2022-07-14 18:23 +0200 |
| Subject | phpdoc: function return type |
| Message-ID | <tapfta$1cl9$1@gioia.aioe.org> |
/**
* @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?
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2022-07-14 19:04 +0200 |
| Message-ID | <jjb0ktFepdqU1@mid.individual.net> |
| In reply to | #19062 |
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
[toc] | [prev] | [next] | [standalone]
| From | Tommy <ba@ve.net> |
|---|---|
| Date | 2022-07-15 15:52 +0200 |
| Message-ID | <tarrfo$1nr6$1@gioia.aioe.org> |
| In reply to | #19063 |
Il 14/07/22 19:04, J.O. Aho ha scritto: >... thanks
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web