Hi!

Let's call this proposal what it is -- strict typing. The auto-cast is (1)
mere fog in this discussion and (2) useless.

(1) fog

function foo( (int) $bar) {}
foo($bar);

is exactly the same, with strict typing, as

function foo(int $bar) { }
foo( (int) $bar);

No it is not the same. There's a huge omission here. The thing that you are not taking into account is that when you have strict typing, you must always ensure correct type, otherwise your script will bomb out. And writing type conversion in EACH call is unfeasible and unmaintaninable - nobody writes their code this way and nobody ever will. So in practice the *real* code would end up looking just foo($bar) - and then consider what happens if "1" comes in. With strict typing it would just drop dead, with optional "I dropped dead, please contact system administrator" screen displayed to the user. Now the question is how you ensure that doesn't happen too much? You have to propagate strict typing through ALL your code - it's not optional anymore, if you have one piece of code strictly typed - everything that touches it has to be strictly typed too, otherwise it may blow up on any call. And since variables have no types, in a couple of months you'll demand strictly typed variables - otherwise how you can keep track of did you already (int) that $bar variable or you didn't yet? You can't insert (int) on every assignment and every method call, right? So what you get at the end is fully strictly typed language - which I suspect is what strictly typing folks is actually after, without maybe realizing it. Which is fine - strictly typing is OK - but it's not PHP. It's some other language with syntax remotely resembling PHP.

Now, I assumed passing a variable of a different type forces a
conversion/copy. Is this necessary? Why not pass the original zval? I see
these scenarios:

Performance doesn't matter here, microoptimizing when designing language syntax is usually bad idea. What matters is what one would expect to happen when the variable is marked as int/string/bool. I think more reasonably it'd be actual int/string/bool than "something that could be eventually converted to int/string/bool".
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to