All:

I'm in favor of this so-called "Weak" typing Zeev has proposed as
well, but I would like to see it become available in PHP before PHP 6.
That doesn't mean it has to go into 5.3.x, but I don't see why there
can't be a 5.4 that includes it. Personally, I think primitive typing
has a much more immediate need than many of the features proposed for
6 and, considering there is already been numerous working patches that
implement this feature in principal, I don't see why we can't have a
5.4 release including it. Waiting for PHP 6 is too long and the many
serious time-consuming tasks that are required to achieve the goals of
PHP 6 shouldn't stop a very useful feature like this from getting into
the wild promptly.

Secondly, I'd like to discuss a little something I thought about
regarding when PHP will/will not throw an error dealing with primitive
types. Specifically when dealing with user input (which always comes
across as a string to start), if you had something like...

function foo(int $a, int $b) { return $a + $b; }

and called:

foo($_GET['a'], $_GET['b']); // $_GET['a'] === "foo", $_GET['b'] === 5

According to Zeev's description of the behavior this would cause a
fatal error, as $_GET['a'] cannot be converted to an integer value.. I
like that, but I think we need to devise a mechanism that allows you
to catch this error at runtime and write application logic around
it... In the simple case above the point would be to be able to catch
the error so that the requesting user could be informed he must enter
two integer values. Off the top of my head the only mechanism that I
can think of would be to throw an exception, which I'm not crazy about
either:

try
{
    print foo($_GET['a'], $_GET['b']);
} catch(TypeCheckException $e) {
    print "Sorry, you need to provide two integer values!";
}

Personally I really like the practical feel and ease of understanding
of using an exception in this case, but the idea of an exception being
thrown from potentially procedural code isn't the best thing to me..

John

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

Reply via email to