Re: type hinting

From: Date: Sun, 06 Jan 2008 20:48:01 +0000
Subject: Re: type hinting
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-34543@lists.php.net to get a copy of this message
On Jan 6, 2008 9:37 PM, Stefan Priebsch <stefan.priebsch@e-novative.de> wrote: > I'm a little afraid that introducing type hints will have us end up with > code like this (to stick with a previous example): > > <?php > > function foo(int $a) {} > > foo((int) '5'); > > ?> > > So, just to make sure, add Java-ish typecasts everywhere. I'm not sure > if that solves the problem (error handling still required when the cast > is not possible), but maybe someone could comment on the performance > implications of adding explicit typecasts in every function call? When a method or function uses the strict typing, it is on purpose. It is documented (self documented and hopefully using normal docs). There is no need of error handling, it is an usage error and should raise a E_{whatever}, be happy, it will not be fatal as it is now in all these OO strictness (with or without good reasons :). About performance, I doubt there is any difference. The cast is done at some point anyway. And the function/method will not have to add these horrible tests like is_int, is_numeric and all other related tests. -- Pierre http://blog.thepimp.net | http://www.libgd.org

« previous php.internals (#34543) next »