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

From: Date: Mon, 14 Jul 2014 17:14:46 +0000
Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-75494@lists.php.net to get a copy of this message
On Mon, Jul 14, 2014 at 06:09:22PM +0100, Andrea Faulds wrote: > > On 14 Jul 2014, at 18:01, Alain Williams <addw@phcomp.co.uk> wrote: > > > But if you have: > > > > function foo(int $a) { > > ... > > $a = 3 / 2; > > } > > > > What do you expect $a to contain ? I would suggest integer 1. > > I’d expect (and I think most people new to PHP would expect) what 3/2 would be in normal > maths, i.e. the fractional value 0.666…. Actually, this makes a good case for return type hinting, > as you could ensure you’d get an integer result here. (But that is another matter.) I trust that you meant 1.5 not 0.666. I would have expected 1 - since it appears, from the code, that $a should only contain integers. -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

« previous php.internals (#75494) next »