Reply
What returns if variable is not set?
Old 11-07-2004, 07:41 PM What returns if variable is not set?
foobar's Avatar
Extreme Talker

Posts: 225
Quick question for you guys.

Can anyone tell me what a variable returns if it isn't set?

Code:
$foo = $_POST['bar'];
What will $foo contain if say, the page was accessed directly and the form never filled? I want to know if it's just empty, or if null is it'S value.

Thanks .
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
When You Register, These Ads Go Away!
Old 11-07-2004, 07:46 PM
Skilled Talker

Posts: 68
Location: Georiga
its will contain nuthing
__________________
Nobody is offline
Reply With Quote
View Public Profile Visit Nobody's homepage!
 
Old 11-07-2004, 07:53 PM
foobar's Avatar
Extreme Talker

Posts: 225
Nothing, as in empty, or as in null?
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-07-2004, 08:01 PM
Skilled Talker

Posts: 68
Location: Georiga
they are the same thing null = ""
__________________
Nobody is offline
Reply With Quote
View Public Profile Visit Nobody's homepage!
 
Old 11-07-2004, 10:20 PM
foobar's Avatar
Extreme Talker

Posts: 225
Oh. That I didn't know.

In other languages (VB, C#, C++, etc.) empty ("") and null (or nothing) are entirely different.

Thanks for the clear up .
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-07-2004, 10:31 PM
Skilled Talker

Posts: 68
Location: Georiga
well in php it is pretty much user firendly... I have used both for my work... I guess you would say null is for when the variable type isn't even defined and empty is when the file type is defined but with no information. But they work the same for me :P
__________________
Nobody is offline
Reply With Quote
View Public Profile Visit Nobody's homepage!
 
Old 11-07-2004, 11:15 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
In php the type is automatically cast so a variable passed with no value would be a string by default. Not null.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-08-2004, 12:03 AM
foobar's Avatar
Extreme Talker

Posts: 225
Alrighty. I'll keep that in mind.

Ah, the joys of programming many languages ...
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-08-2004, 04:18 AM
nick89's Avatar
Super Talker

Posts: 136
Location: Brisbane, Australia
the best thing to do is use isset($_POST['bar'])
nick89 is offline
Reply With Quote
View Public Profile Visit nick89's homepage!
 
Old 11-08-2004, 04:45 PM
Christopher's Avatar
Iced Cap

Posts: 3,111
Location: Toronto, Ontario
I like to set error reporting to E_ALL so you cannot use variables before they are initialized, makes for more secure scripts and better programming practice. Then you just use isset() like nick89 suggested.

After development is complete, you can just stick error reporting back to normal if you'd like.
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 11-10-2004, 11:00 AM
Skilled Talker

Posts: 97
Quote:
Originally Posted by Chroder
I like to set error reporting to E_ALL so you cannot use variables before they are initialized, makes for more secure scripts and better programming practice. Then you just use isset() like nick89 suggested.

After development is complete, you can just stick error reporting back to normal if you'd like.

Unfortunately most of us do not have control of the PHP error reporting setting in the server that is hosting our website
daboss is offline
Reply With Quote
View Public Profile Visit daboss's homepage!
 
Old 11-10-2004, 11:12 AM
Republikin's Avatar
Super Moderator

Posts: 3,191
Well fortunate for you the good people over at php decided to make a function just for that...

error_reporting(E_ALL)
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 06:13 AM
nick89's Avatar
Super Talker

Posts: 136
Location: Brisbane, Australia
error_repoting(E_ALL);
</ semi-colon nazi>
nick89 is offline
Reply With Quote
View Public Profile Visit nick89's homepage!
 
Old 11-11-2004, 09:39 AM
Republikin's Avatar
Super Moderator

Posts: 3,191
Oh, I was giving the person a benefit of a doubt. You know, that they knew where semicolons went.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 10:08 PM
Skilled Talker

Posts: 97
well, i learnt something today... thanks captain o my captain...
daboss is offline
Reply With Quote
View Public Profile Visit daboss's homepage!
 
Old 11-11-2004, 10:13 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
No problem boss
Republikin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to What returns if variable is not set?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.17550 seconds with 12 queries