RE: [PHP-DEV] Scalar Type Hinting

From: Date: Thu, 08 Mar 2012 03:48:14 +0000
Subject: RE: [PHP-DEV] Scalar Type Hinting
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-58764@lists.php.net to get a copy of this message
From: Simon Schick [mailto:simonsimcity@googlemail.com] > > > > I consider interchangeable only three cases: > > 1. Numerical string. > > 2. Integers and floats as strings. > > 3. Integer and string  0 1 as bool. > > > > Any other cases should error out. > > Until now I thought about the weak variable-types as a order ... > string, float, integer, Boolean. > All Boolean values are compatible be an integer (0 or 1) and all > integer are compatible to a float and so on. Do you think it's > good to have it this way? This would mean that you could also get > a Boolean true as string "1" ... I personally don't like that ... > but I don't know where to draw the strict-line. > Now think about that backwards. Can a "1" be passed as a parameter > that expects Boolean? If yes, I'd keep it consistent in both ways. > > Bye > Simon Conversion the other way is essential. Consider the following URL: http://example.com?foo=1 In your PHP script $_GET['foo'] === '1' (a string). In fact, nearly every input to PHP is a string. This is why PHP was designed with some seriously robust type juggling on scalars. Any typing proposal that wants to actually pass a vote is going to have to allow appropriate implicit conversions from string to other types. John Crenshaw Priacta, Inc.

« previous php.internals (#58764) next »