I agree that Return type hinting needs to be aligned with parameter type
hinting. That's basically what I said in previous post, that without
parameter type the return type hinting is not very useful, it's like
half-baked

While web isn't typed, the php is not just for the web anymore, or is it?
Some databases expect typed input, else the data is not found. 
For example passing string '1' instead of number 1 will not cause any errors
when searching MongoDB but you will not get the result you expect to get if
the value of key is integer 1

Strong typing just helps, adds sanity to your program. The fact that it can
be made optional and not required is a great benefit also.


Dmitri Snytkine
Web Developer
Ultra Logistics, Inc.
Phone: (888) 220-4640 x 2097
Fax: (888) 795-6642
E-Mail: dsnytk...@ultralogistics.com
Web: www.ultralogistics.com

"A Top 100 Logistics I.T. Provider in 2011"


-----Original Message-----
From: Rasmus Lerdorf [mailto:ras...@lerdorf.com] 
Sent: Thursday, December 22, 2011 1:41 PM
To: Keloran
Cc: Dmitri Snytkine; Alain Williams; internals@lists.php.net
Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC

On 12/22/2011 07:08 AM, Keloran wrote:
> i would love to see this expanded aswell (the way type hinting on function
> variables was supposed to be), so that it could be
> 
> string, int
> 
> e.g.
> function int test(bool $tester) {
>  if ($tester) { return 5; }
>  return 99;
> }

Return type hinting needs to be aligned with parameter type hinting, and
as has been pointed out many times on this list, type hinting for
interchangable scalar types is a really bad idea. It will push all type
checking up to the caller of the underlying functions/methods. PHP is
primarily a Web scripting language and the Web isn't typed. Having stuff
like this break:

if(age_check($_POST['age'])) { do_stuff(); }

because the author of the age_check() function added an int type hint
just doesn't make any sense. It would cause everyone to have to start
casting things everywhere, just in case. eg.

if(age_check((int)$_POST['age'])) { do_stuff(); }

This is not a step forward. If the author of age_check() really doesn't
want to accept type-juggled arguments, then it is easy enough to do a
strict type check in the function itself. This puts the effort in the
correct place and doesn't encourage this type of coding.

-Rasmus

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


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

Reply via email to