Re: Type hinting

From: Date: Wed, 26 May 2010 21:43:35 +0000
Subject: Re: Type hinting
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-48480@lists.php.net to get a copy of this message
Hi!
You could just as easily say to do: function foo($bar) { $bar = (int) $bar; } /.../
Why bother with either if that's the case? Why not add support for something like:
Indeed, why bother? Only reason I heard so far is documentation. Which applies to both cases, but as you noted, it could be part of docblock. It is easier to handle though it were part of the function definition (reflection, etc.) But in general, yes, you can do it manually. Strict typing though adds additional problem that you don't have a point to handle the failure - and don't talk to me about error handlers, they are useless in this situation as they are too generic to know what's actually being handled. With coercive typing it is true too, but there you have much more reason to expect success, since it would not trip on things like string<->int or int<->bool. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

« previous php.internals (#48480) next »