declaring var of type

I've just read that a var can be declared in php as follows:
string $var1;
integer $var2;
etc.
Here >>
http://marakana.com/blog/examples/php-data-types-and-convers ions-between-them.html
They aren't talking about casting.
I've never seen this before and trying it in vers 5.0.3.3 shows that it has
no idea about it either.
Am I missing something?
TIA
Vince
Vince Morgan [ Fr, 20 April 2007 16:16 ] [ ID #1693627 ]

Re: declaring var of type

"Vince Morgan" <vinhar [at] REMOVEoptusnet.com.au> wrote in message
news:4628caca$0$11788$afc38c87 [at] news.optusnet.com.au...
Looking at some of their examples seems whoever wrote them doesn't know
about it either.
Vince Morgan [ Fr, 20 April 2007 16:21 ] [ ID #1693628 ]

Re: declaring var of type

"Vince Morgan" <vinhar [at] REMOVEoptusnet.com.au> wrote in message
news:4628caca$0$11788$afc38c87 [at] news.optusnet.com.au...
| I've just read that a var can be declared in php as follows:
| string $var1;
| integer $var2;

well, the above is both casting and declaring...

// cast

(string) $var1;

// declaring

string $var1;

| They aren't talking about casting.
| I've never seen this before and trying it in vers 5.0.3.3 shows that it
has
| no idea about it either.

there are more formal ways to cast in php. and you know me, i'm kind of
religious about code. :)

i use things like floatval(), intval(), bool()...and then settype().

now for all of this casting and typing, php itself does precious little even
when it knows you've typed the data explicitly. really, it helps you in
comparisons in statements/functions (i.e. if/then, function()). it also
helps you get correct output to the browser...as in using sprint_f, or,
ooooh, how about implicit casting using number_format (even though a string
is returned).

anyway, hth.
Steve [ Fr, 20 April 2007 17:46 ] [ ID #1693631 ]

Re: declaring var of type

"Steve" <no.one [at] example.com> wrote in message
news:Kc5Wh.1423$go5.521 [at] newsfe12.lga...
>
> "Vince Morgan" <vinhar [at] REMOVEoptusnet.com.au> wrote in message
> news:4628caca$0$11788$afc38c87 [at] news.optusnet.com.au...
> | I've just read that a var can be declared in php as follows:
> | string $var1;
> | integer $var2;
>
> well, the above is both casting and declaring...
>
> // cast
>
> (string) $var1;
>
> // declaring
>
> string $var1;
>
> | They aren't talking about casting.
> | I've never seen this before and trying it in vers 5.0.3.3 shows that it
> has
> | no idea about it either.
>
> there are more formal ways to cast in php. and you know me, i'm kind of
> religious about code. :)
>
> i use things like floatval(), intval(), bool()...and then settype().
>
> now for all of this casting and typing, php itself does precious little
even
> when it knows you've typed the data explicitly. really, it helps you in
> comparisons in statements/functions (i.e. if/then, function()). it also
> helps you get correct output to the browser...as in using sprint_f, or,
> ooooh, how about implicit casting using number_format (even though a
string
> is returned).
>
> anyway, hth.
>
>
Thanks Steve. I found if I use brackets it worked. I'm glad you cleared up
it's limited usefullness. Was beginning to feel like to C ish ;)
Vince
Vince Morgan [ Fr, 20 April 2007 19:43 ] [ ID #1693632 ]

Re: declaring var of type

"Vince Morgan" <vinhar [at] REMOVEoptusnet.com.au> wrote in message
news:4628fb8c$0$5748$afc38c87 [at] news.optusnet.com.au...

errr, read, "Was beginning to feel too C ish"
Vince Morgan [ Fr, 20 April 2007 19:49 ] [ ID #1693634 ]

Re: declaring var of type

| Thanks Steve. I found if I use brackets it worked. I'm glad you cleared
up
| it's limited usefullness. Was beginning to feel like to C ish ;)

sorry, i should have shown the declaration too. it's only as a param that
will work, i.e.:

function hello(string $world);

anyway, hth...and no prob.
Steve [ Fr, 20 April 2007 20:19 ] [ ID #1693636 ]
PHP » alt.php » declaring var of type

Vorheriges Thema: PEAR::HTML_BBCodeParser Parser Issue
Nächstes Thema: what chart component is this php site using?