RE: [PHP-DEV] Type hinting

From: Date: Thu, 27 May 2010 15:47:10 +0000
Subject: RE: [PHP-DEV] Type hinting
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-48528@lists.php.net to get a copy of this message
On Thu May 27 11:22 AM, David Soria Parra wrote: > On 2010-05-27, Zeev Suraski <zeev@zend.com> wrote: > +1 from me for this. I think two solutions is not the right way and we > +should > try to make the type system consistent for the user. Therefore +1 for > auto-converting. I still feel the debate of the "right way" is still open, say I have the following class: class Tax { /** * Apply a tax rate or {@link getRatesApply() tax rates} to a given amount and get the total tax. * * @param string|float $amount * @param string|float|array $rates Tax rate or an array of tax rates * @param int $precision Rounding precision * * @return string */ static function apply($amount, $rates, $precision = 2) {} } Strict typing would allow: static function apply($amount, $rates, int $precision = 2) {} Type hinting would allow: static function apply(string $amount, $rates, int $precision = 2) {} This is far from consistent to the user, the syntax is identical to *strict typing* in many (if not all) dynamic programming languages. I would much prefer to see a 'type hint' where magical conversion happens as: static function apply((string) $amount, $rates, (int) $precision = 2) {}

« previous php.internals (#48528) next »