[KLUG Members] PHP strict.

bill members@kalamazoolinux.org
Sat, 03 Aug 2002 16:43:02 -0400


Not really.  Different philosophy at work to accomplish a different goal.

You can set the error level high if you want to flag uninitialized values, but
realize it doesn't make sense to fix the variable type in advance in an
environment where you can't define in advance the value (string, integer, float,
etc.) of a field on an HTML form.  There is no <input type=integer> in html.
Old word processors had no spell check before printing, HTTP has no type check
before submitting a form..  The user sends all their data all at once, then the
server (with your programming) processes it and replies.

You can check the type once it arrives and is assigned to a variable, and then
your code should reply back to the browser with a new html reply that the error
needs correction.

Within HTTP there's no way to check individual fields without submitting the
entire document, and there's no way to reply to individual errors except with
another whole document.  There's no HTTP error code that means "whoops, that
value is the wrong type."  Even if there was, the form (and it's values) would
be history already.  You may use javascript or other client scripts to check
before submission, but that, again, is outside PHP because it is outside HTTP.

Variable typing is just one way of checking values.  Learn to test the values
you're working with before you use them and you'll develop more robust code and
you'll find it will work pretty smooth.

kind regards,

bill

Richard Vincent wrote:

> Wow ... that is pretty disturbing.
>
> -----Original Message-----
> From: members-admin@kalamazoolinux.org
> [mailto:members-admin@kalamazoolinux.org] On Behalf Of bill
> Sent: Saturday, August 03, 2002 1:45 PM
> To: members@kalamazoolinux.org
> Subject: Re: [KLUG Members] PHP strict.
>
> Short answer, no.
>
> Variables are treated as strings by default.  It is not necessary to
> define them
> in advance.  You can test values for whatever type you want, and PHP
> will handle
> values however you want.
>
> For example:
>
> $var=1;
> $anothervar=2;
>
> $myvar = $var + $anothervar;
> // myvar will be 3;  because this is math (+), it assumes numbers
>
> $myvar = $var . $anothervar;
> $myvar will be "12";  // because this is concantenation (.), it assumes
> characters,
> // So, this is the string "1" with the string "2" appended.
>
> kind regards,
>
> bill
>
> Richard Vincent wrote:
>
> > Hello,
> >
> > I'm in the process of learning PHP and I have a quick question. Is
> there a way
> > to use strict variable declaration inside of PHP? . Because right now
> I get an
> > error when I try and declare my variables at the top of my programs..
> >
> > Thank You
> >
> > Richard Vincent
> >
>
> _______________________________________________
> Members mailing list
> Members@kalamazoolinux.org
> 
> _______________________________________________
> Members mailing list
> Members@kalamazoolinux.org
>