Re: Type hinting

From: Date: Thu, 27 May 2010 08:58:02 +0000
Subject: Re: Type hinting
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-48494@lists.php.net to get a copy of this message
On 27.05.2010, at 10:45, Daniel Egeberg wrote: > If you don't know whether the user/database provided information you > have is correct before you pass it along to something else, I would > say that the code indeed is bad. Unless you regard "123abc" as a valid > value from your user, don't allow the user to give you that value. If > you regard it as a valid value, then it's not an int thus you wouldn't > want to type cast it in the first place. as Arvids already pointed out most database extensions for PHP atm return strings even for integers/floats. furthermore the "123abc" example was mentioned more for data coming from external sources, with strict typing you are encouraging stuff like (int)"123abc". Of course a good programmer would first check with is_numeric() before casting. Seems like a lot of work. With the proposal of weak typing with error/notice on data loss none of that would be needed. regards, Lukas Kahwe Smith mls@pooteeweet.org

« previous php.internals (#48494) next »