Re: [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Mon, 14 Jul 2014 17:06:19 +0000
Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-75490@lists.php.net to get a copy of this message
On Mon, Jul 14, 2014 at 11:01 AM, Alain Williams <addw@phcomp.co.uk> wrote: > On Mon, Jul 14, 2014 at 12:25:22PM -0400, Anthony Ferrara wrote: > >> IMHO, strict hints are dangerous in the context of PHP because PHP's >> types can change in unpredictable ways. A variable that was an integer >> can turn into a float through seemingly integer operations. Example: >> $a / $b * $b will result in a float unless $b divides $a (even though >> for sane values of $a and $b, it will be exactly representable as an >> int). > > But if you have: > > function foo(int $a) { > ... > $a = 3 / 2; > } > > What do you expect $a to contain ? I would suggest integer 1. I would expect the same result as 3.0 / 2.0, as would most every new programmer.

« previous php.internals (#75490) next »