xploita Posted April 27, 2007 Share Posted April 27, 2007 how do i initialize each variable type in php? i mean..do i initialize all of them to NULL ? thx Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 27, 2007 Share Posted April 27, 2007 you don't need to initialize variables in PHP Quote Link to comment Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 you dont have to initialize variables in php... $var='test'; $var=1; $var=true; all of which work fine Quote Link to comment Share on other sites More sharing options...
xploita Posted April 27, 2007 Author Share Posted April 27, 2007 i know that i don't HAVE to,but it's better for security concerns that i do so. so ! Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 27, 2007 Share Posted April 27, 2007 NULL, TRUE/FALSE, '' Those will all work fine ('' <- is an empty string) Quote Link to comment Share on other sites More sharing options...
xploita Posted April 27, 2007 Author Share Posted April 27, 2007 so,u mean i'll be using NULL for all variable types? or true/false for boolean '' for strings another thing,which is better.to use isset or just if($varname) to check if the variable has a value ? regards Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 27, 2007 Share Posted April 27, 2007 I would use isset/empty, unless it is a boolean then you could use if($varname), and for the NULL var, your could do if(is_null($varname)) here are some good ways to return true/false values: isset() is_bool() is_numeric() is_float() is_int() is_string() is_object() is_array() Quote Link to comment Share on other sites More sharing options...
xploita Posted April 27, 2007 Author Share Posted April 27, 2007 that's for checking if the variables were initialized or not. still u didn't confirm about initializing them(in the begining of the script) correct me if i'm wrong. $string =''; $boolean = true/false; $array=array(); $int/$double=NULL; what about objects? regards Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.