Re: Question: Should exit() print out the integer exit-status?
| From: | Vlad Krupin | Date: | Wed, 19 Dec 2001 23:11:35 +0000 |
| Subject: | Re: Question: Should exit() print out the integer exit-status? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-74462@lists.php.net to get a copy of this message | ||
Please, understand me correctly - I have nothing against exit() working in the same manner regardless of the type of the argument. I would love to see that. The problem is that (1) it already accepts a string, and has been working that way for a long time, so this can't go away, and (2) there is no other way (AFAIK) to set exit codes, and some people need that. Those are somewhat contradicting requirements, so we might have to compromise.
I do have a problem with the compromise you proposed though, if I understood you correctly. You suggest using something like
exit("1boo") And having exit() parse the first digit out. That's BAD. What if someone already uses exit("123, 456 servers are unavailable"); or something similar. How should we parse something like that? Chances of that are slim, but just as good as Zeev's argument where he says that there are scripts out there that rely on the current implementation of exit(), e.g. one of his own. Jamming two values into a storage space designed for a single value (a string) is bad :(Vlad Lars Torben Wilson wrote:
Vlad Krupin writes:Lars Torben Wilson wrote:No, it's called loose typing. See http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion We have a language here which considers the integer value of "5" to be 5, and an exit() construct which ignores that. For instance: shanna% php -q <?php exit('5'); ?> 5 shanna% echo $? 0 shanna% php -q <?php exit(5); ?> 5 shanna% echo $? 5 How much sense does this make? None, as far as I can see. What I'm proposing is to make the behaviour of exit() _not_ depend on the type of its argument. At present if the argument is an integer exit() prints it and sets the error status, but if it's any other type, exit() just prints it and doesn't set the exit status. This is more complex than my proposal: no matter what the argument is, print out its string value, and set the exit status to its integer value. AFAICT exit() is currently broken wrt how it handles the type of its argument.Perhaps I have not explained my position. I don't care whether it outputs the exit status as a string--as long as it sets the error code appropriately *as well*. By appropriately, I mean that 'exit("boo");' would a) print 'boo' and b) return with exit status 0, but 'exit("1boo")'; would a) print '1boo' and b) return with exit status 1. This would be consistent with PHP's type conversion rules, and would also tend to behave in the way that the programmer expects it to.Yikes. This is way worse than overloading. In school they called that data-coupling, I think. In real life this is called a hack. Sorry, but a -1 on this. Vlad