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

From: Date: Sun, 13 Jul 2014 14:20:43 +0000
Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-75399@lists.php.net to get a copy of this message
On 13 Jul 2014, at 13:09, Nikita Popov <nikita.ppv@gmail.com> wrote: > I haven't yet closely reviewed the details of what is and isn't allowed, > but one things I would strongly recommend against is introducing any > "accept but throw a notice" cases. Either a value is allowed or it isn't. > "12foo" to an int/float argument should throw a recoverable fatal error, > like everything else. (I'd change that in zpp as well, but that's a > different discussion). I’ve changed this case in the RFC and my patch. Previously, “12foo” would just throw an E_NOTICE, but now it is not accepted: Integer hints: function foo(int $a) { var_dump($a); } foo(1); // int(1) foo("1"); // int(1) foo(1.0); // int(1) foo("1a"); // E_RECOVERABLE_ERROR foo("a"); // E_RECOVERABLE_ERROR foo(999999999999999999999999999999999999); // E_RECOVERABLE_ERROR (since it's not exactly representable by an int) foo(1.5); // E_RECOVERABLE_ERROR Float hints: function foo(float $a) { var_dump($a); } foo(1); // float(1) foo("1"); // float(1) foo(1.0); // float(1) foo("1a"); // E_RECOVERABLE_ERROR foo("a"); // E_RECOVERABLE_ERROR foo(1.5); // float(1.5) -- Andrea Faulds http://ajf.me/

« previous php.internals (#75399) next »