RE: [PHP] How to type arguments
| From: | Gautier Di Folco | Date: | Wed, 03 Dec 2008 06:24:31 +0000 |
| Subject: | RE: [PHP] How to type arguments | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284034@lists.php.net to get a copy of this message | ||
> Date: Tue, 2 Dec 2008 19:39:53 -0700> From: quickshiftin@gmail.com> To:
> nrixham@gmail.com> CC: richard@php.net; xgx26xdf@hotmail.com; php-general@lists.php.net>
> Subject: Re: [PHP] How to type arguments> > On Tue, Dec 2, 2008 at 1:49 PM, Nathan Rixham
> <nrixham@gmail.com> wrote:> > > Richard Heyes wrote:> >> >> I'm a
> french student, sorry for my mail :> >>>> >>> I want to know how can I type
> my functions' arguments ?> >>>> >>> It is heavy to do :>
> >>> function post($id)> >>> {> >>> $id=(int)$id;> >>>
> //...> >>>> >>> >> PHP is loosely typed so strictly (...) speaking,
> that would be fine.> >> However, you're best off making sure that what you've
> been given is> >> what you think it is. Ergo, what you've written, is what I would
> do.> >>> >> or tu put (int) before each use...> >>>> >>>
> >> Not necessary to put it there for each use, just the first.> >>> >>>
> > also worth noting that you can type-hint as long as the type you're hinting> > is an
> object and not a primitive:> >> > function post(SomeObject $obj)> > {> > //
> php will effectively throw a catchable fatal error if> > // $obj is not an instance of
> SomeObject> > }> >> > sadly you can't:> >> > function post(int
> $number)> > {> > // doesn't work for primitives> > // but then php has
> limited primitive types :(> > }> > > however, type-hinting does support arrays>
> > function alterArr(array $a) { #.. }> > -nathan
Ok, thank you,
> > type-hint as long as the type you're hinting> > is an object and not a
> > primitive:
yes, but it is heavyer than doint $v=(int)$v;
It is all right
thank you
_________________________________________________________________
Email envoyé avec Windows Live Hotmail. Dites adieux aux spam et virus, passez à Hotmail !
C'est gratuit !
http://www.windowslive.fr/hotmail/default.asp