Re: [PHP] Re: How to declare Vars in PHP?

2005-05-05 Thread Rory Browne
Next time you double post(I'm assuming by accident), could you reply
to one, of the posts declaring it void, and point people to the other,
so that you don't have two people answering the same question in two
different threads.

On 5/5/05, Ryan Faricy <[EMAIL PROTECTED]> wrote:
> 
> "Jon M." <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >I know it's not necessary, but I still want to know how.
> >
> >
> > I know in JavaScript, that you declare vars like so:
> >
> > var = variableName;
> >
> > So I'm assuming that in PHP you do it like this:
> >
> > var = $variableName;
> >
> > But there doesn't seem to be a single shred of documentation on PHP.net
> > (or in ANY book) that covers this. All they say is that it's good
> > practice, but not necessary. Then they always skip telling you how.
> >
> > I always like to declare vars since it helps me keep track of the vars I
> > will be using, and I just like to do things right.
> >
> > So am I right about how you do it? "Yes", "No", example please??
> >
> >
> > -Jon
> 
> It is good practice to define your variables (i.e., set them to 0, or empty,
> etc) at the beginning of a script, for security and reliability reasons.
> 
> With PHP however, there technically is no definition of variables as in
> other languages such as Java or BASIC. To define a variable in PHP simply
> requires a $variableName = ''; or $variableName = 0; or $variableName =
> empty; etc etc. A variable is defined as soon as a value is set for it,
> therefore to define a variable, simply give it a value.
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: How to declare Vars in PHP?

2005-05-05 Thread Jon M.
OK, thanks everyone.



(BTW -I actually meant to say 'var $varName;' in PHP and 'var varName;' in 
JavaScript -doh!)



Anyway, my question has been thoroughly answered, and I completely 
understand now.



I did try the "var $varName;" outside a class, just to see what happened, 
and found out it does indeed throw a parse error, so I'll just use a comment 
as Mr. Rasmus suggested. I wonder why "Beginning PHP 5 and MySQL from Novice 
to Professional by W. Jason Gilmore" says to declare them? I guess he just 
meant by assigning a value like: $varName = Null or something. I just have 
to get used to this new way of "declaring" -lol.



And thanks especially Ryan. That is a very informational answer, and gives 
me a much deeper insight into why PHP doesn't allow an actual definition, 
than any other resource/explanation I have ever seen! Thank you VERY much 
for taking the time to write that, I am the kind of person who wants to 
completely understand a subject (not just "how", but, "why" as well), and 
now I completely understand this particular part of PHP.



-Jon






"Ryan Faricy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> "Jon M." <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>>I know it's not necessary, but I still want to know how.
>>
>>
>> I know in JavaScript, that you declare vars like so:
>>
>> var = variableName;
>>
>> So I'm assuming that in PHP you do it like this:
>>
>> var = $variableName;
>>
>> But there doesn't seem to be a single shred of documentation on PHP.net 
>> (or in ANY book) that covers this. All they say is that it's good 
>> practice, but not necessary. Then they always skip telling you how.
>>
>> I always like to declare vars since it helps me keep track of the vars I 
>> will be using, and I just like to do things right.
>>
>> So am I right about how you do it? "Yes", "No", example please??
>>
>>
>> -Jon
>
> It is good practice to define your variables (i.e., set them to 0, or 
> empty, etc) at the beginning of a script, for security and reliability 
> reasons.
>
> With PHP however, there technically is no definition of variables as in 
> other languages such as Java or BASIC. To define a variable in PHP simply 
> requires a $variableName = ''; or $variableName = 0; or $variableName = 
> empty; etc etc. A variable is defined as soon as a value is set for it, 
> therefore to define a variable, simply give it a value. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: How to declare Vars in PHP?

2005-05-05 Thread Ryan Faricy

"Jon M." <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I know it's not necessary, but I still want to know how.
>
>
> I know in JavaScript, that you declare vars like so:
>
> var = variableName;
>
> So I'm assuming that in PHP you do it like this:
>
> var = $variableName;
>
> But there doesn't seem to be a single shred of documentation on PHP.net 
> (or in ANY book) that covers this. All they say is that it's good 
> practice, but not necessary. Then they always skip telling you how.
>
> I always like to declare vars since it helps me keep track of the vars I 
> will be using, and I just like to do things right.
>
> So am I right about how you do it? "Yes", "No", example please??
>
>
> -Jon

It is good practice to define your variables (i.e., set them to 0, or empty, 
etc) at the beginning of a script, for security and reliability reasons.

With PHP however, there technically is no definition of variables as in 
other languages such as Java or BASIC. To define a variable in PHP simply 
requires a $variableName = ''; or $variableName = 0; or $variableName = 
empty; etc etc. A variable is defined as soon as a value is set for it, 
therefore to define a variable, simply give it a value. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php