On 11 September 2014 04:02:43 GMT+01:00, Park Framework
<[email protected]> wrote:
>> You know, “int”, “float”, “string” etc. aren’t currently reserved
>words.
Well, they are in the context of casts:
$a = (int)'42';
$a = (string)42;
etc
> We could add functions, or even make them reserved words and add
>internal functions (à la isset), so int(‘2’), float(‘2.0’),
>string(‘test’) etc.
How would this be different from what we already have? For the function version
(useful as a callback), we have intval(), strval(), etc
>>
>> Or perhaps class-like constructors? $a = new int('2'); ? Would kinda
>make sense given some people want to add methods to primitive types.
>
>+1
>
>$int instanceof Int
>$float instanceof Float
>$num instanceof Numeric
>$bool instanceof Boolean
>$str instanceof String
>$array instanceof Array
>
>This makes it possible not to use the is_*() functions.
>It is desirable to conduct instanceof fully consistent with behavior
>hinting casts, it would be logical and correct.
>Just wanted to be able to use these classes (or interfaces) to create
>their objects, these objects would pass inspection in hinting casts.
This could cause a lot of confusion. If these "constructors" are just a new
syntax for type casting, there's no obvious reason to behave differently in
terms of strictness, which is what we were discussing previously. Worse, they
would look like objects, but behave as plain variables (no reference-like
ability to modify the value in place).
Alternatively, these could be special "boxed types", which were real objects
acting almost but not quite the same way as the equivalent basic type. Some
languages (e.g. Java) have those, but they're frankly rather confusing, and I'm
not sure what the benefit would be.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php