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 Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/ 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 Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/#findComment-239857 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 Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/#findComment-239859 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 ! Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/#findComment-239861 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) Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/#findComment-239867 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 Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/#findComment-239870 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() Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/#findComment-239874 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 Link to comment https://forums.phpfreaks.com/topic/48958-initializing-variables/#findComment-239887 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.