Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15528
| From | Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: PHP7 Stack Trace Mess |
| Date | 2015-06-25 18:04 +0200 |
| Organization | albasani.net |
| Message-ID | <mmh8pr$mff$1@news.albasani.net> (permalink) |
| References | (8 earlier) <mmeu5v$ibm$1@news.albasani.net> <mmfdas$5g7$1@solani.org> <87mvzo4jtr.fsf@ahungry.com> <mmgchq$cf2$1@news.albasani.net> <mmh0rk$gj$1@solani.org> |
On 25/06/15 15:48, Christoph M. Becker wrote:
> It is the only way to let the user (opposed to library developers)
> decide whether weak or strict type checking should be applied.
Shouldn't the mere presence (or absence) of scalar type hints in a
function declaration serve this purpose? If you absolutely want weak
typing, you simply don't use type hints (nor strict libraries).
> Well, you'll want to consider the background. "Everybody" wanted scalar
> type hints, but no broad consensus could be achieved regarding the
> semantics (strict vs. weak).
To me, "type hint" implies "strict". If I say "int", I mean "int" and
not "string containing a representation of an integer".
> Apparently, you're in favor of strict type hints, but I am not, because
> it would be a pretty big change in how PHP works, and also there are
> some weird edge cases, e.g.:
>
> <?php
> declare(strict_types=1);
> $num = 1 << 32;
> $num *= $num;
> echo dechex($num);
>
> What's the output?
I consider PHP's built-in functions as being equivalent to functions
without type hinting. And thus the behaviour should not change from what
it currently is.
According to the manual, the signature is
string dechex( int $number )
In your example, $num would be a float, larger than the allowed range
for int. So, taking the manual literally, I would expect this to cause
an error. (The actual output is "0", by the way.) The current behaviour
would be better "hinted" with
string dechex( numeric $number )
which would describe the allowed values more accurately. (Assuming
numeric = bool | int | float | string containing a number.) I do not see
any "weird edge case" here. Currently, the manual is inaccurate by
specifying "int" whereas the function also accepts bools, floats and
numeric strings. The latter fact could even be regarded as an
undocumented feature, since the documentation clearly says "int".
Anyway, I wouldn't call this function with anything else but an integer
argument.
Greetings,
Thomas
--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PHP7 Stack Trace Mess Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-06-23 16:28 +0200
Re: PHP7 Stack Trace Mess Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2015-06-23 16:58 +0000
Re: PHP7 Stack Trace Mess "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-23 20:00 +0200
Re: PHP7 Stack Trace Mess Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-06-23 22:22 +0200
Re: PHP7 Stack Trace Mess "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-24 00:03 +0200
Re: PHP7 Stack Trace Mess Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-06-24 10:44 +0200
Re: PHP7 Stack Trace Mess "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-24 20:02 +0200
Re: PHP7 Stack Trace Mess Matthew Carter <m@ahungry.com> - 2015-06-24 14:09 -0400
Re: PHP7 Stack Trace Mess Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-06-24 20:50 +0200
Re: PHP7 Stack Trace Mess "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-25 01:09 +0200
Re: PHP7 Stack Trace Mess Matthew Carter <m@ahungry.com> - 2015-06-24 22:12 -0400
Re: PHP7 Stack Trace Mess Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-06-25 10:02 +0200
Re: PHP7 Stack Trace Mess "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-25 15:48 +0200
Re: PHP7 Stack Trace Mess Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-06-25 18:04 +0200
Re: PHP7 Stack Trace Mess "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-25 19:14 +0200
Re: PHP7 Stack Trace Mess Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-06-23 22:07 +0200
Re: PHP7 Stack Trace Mess "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-23 22:15 +0200
Re: PHP7 Stack Trace Mess Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2015-06-24 06:13 +0000
csiph-web