Re: Type hinting misunderstood
| From: | Alain Williams | Date: | Sun, 06 Jan 2008 11:28:57 +0000 |
| Subject: | Re: Type hinting misunderstood | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-34522@lists.php.net to get a copy of this message | ||
On Sat, Jan 05, 2008 at 07:34:04PM -0800, Mike Lively wrote:
> input is going to makes it's way into your api at some point. Now of course you can (and
> should) be filtering this
> input before it is used, but if imo when dealing with a loosely typed language where the same
> input could be hinted as an
> int in one function it eventually reaches, and a string in another.
> The point being I understand you may be targeting 'internal stuff' but programming
> (especially web development) is
> centered around manipulating/reading input to perform actions...just because it's not
> 'intended' doesn't mean it's going
> to never happen.
> Also, I am pretty sure PDO returns results from at least mysql and sqlite as strings regardless
> of their type in the
> database...or are results from the database also not something type hints are inteded for?
PLEASE READ CAREFULLY
You have NOT understood what type hinting is about.
You are confusing the TYPE and the VALUE.
What type hinting means is:
* is the TYPE correct ? If so succeed.
* can the VALUE be 100% converted to the desired TYPE (eg '5' to int) ? If so succeed.
* fail
Type HINTING is not type ENFORCEMENT. PHP type juggling is still allowed, so PDO returning results
as strings
is quite OK as long as what is defined to be numeric *really* has a VALUE that is a number.
OK: the above does not apply with some things like resources since you can't convert them
to/from a string
in a meaninful way.
--
Alain Williams
Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
Chairman of UKUUG: http://www.ukuug.org/
#include <std_disclaimer.h>