PyHP_pph icon indicating copy to clipboard operation
PyHP_pph copied to clipboard

How should types be casted?

Open Kampfkarren opened this issue 8 years ago • 1 comments

We can take the C/C++ approach with either (type)value or type(value) or the PHP-esque route of adding functions to the global namespace, such as to_boolean(value), to_int(value), etc.

Kampfkarren avatar Jun 18 '17 02:06 Kampfkarren

It should be implicit, with vaguely defined rules. If, say, you have a function like this:

int Twice(int x)
  {
    return x * 2
  }

And you pass it something that's not an int, say... a boolean:

$Result = Twice(True);
Console.StandardOutputStream >> disp($Result) >> Console.Characters.EndLine;

Then it should convert from boolean to int in an odd, unclearly defined way. In this case, I'd guess the output would be:

2

But it could also be:

0

Or:

example.pyph_pph:1:16: error: Cannot convert boolean to int.

ghost avatar Jun 22 '17 19:06 ghost