Re: [POC Patch] Scalar Type Hinting/Casting - Proof Of Concept

From: Date: Mon, 05 Mar 2012 19:38:01 +0000
Subject: Re: [POC Patch] Scalar Type Hinting/Casting - Proof Of Concept
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-58619@lists.php.net to get a copy of this message
Hi Lazare, I'm a bit divided on your proposal. On one hand I kind of like the simplicity of the syntax and the basic idea behind it: > (int?) $x > > which should be strictly translated to the following, without any way to > change that behavior by any type casting overload system: > > is_null($x) ? null : (int)$x > But on the other hand, I'm not sure you should mix type casting and the short if syntax (which is clearly what inspired the question mark there). This sort of makes me think you're really turning an (int) type casting, into more of a (mixed) type casting... I don't really like that! :) Therefore I'm divided into thinking this is a cool idea, or if I'd get so confused about this I would use it as much as the short if syntax: $var = @$_GET['var'] ?: 'default'; (Which is never, btw!) How about allowing *several entries* per type cast (since spaces are allowed inside casts anyway, but could also be a semicolon or something): $int_or_null = (int unset) $x; This could be usefull for other instances as (string null) or (bool null) as well... Your thoughts? Best regards, ~ Daniel Macedo

« previous php.internals (#58619) next »