Welcome Guest, Not a member yet? Register   Sign In
Undefined variable
#2

[eluser]TheFuzzy0ne[/eluser]
PHP will issue a warning for variables that are called upon, but not set. CodeIgniter is set to show all warnings and errors by default.

Before using a variable that you aren't sure has been set, it's considered good practice to use isset() to confirm that the variable has indeed been set.

Code:
if (isset($variable_name))
{
    // Do something intelligent, without a warning.
}

Another workaround that isn't always as reliable. Simply define your variable at the start of the function. I often do this for clarity, but I don't rely on it throughout my code as a variable can be unset.


Messages In This Thread
Undefined variable - by El Forum - 02-11-2009, 05:02 AM
Undefined variable - by El Forum - 02-11-2009, 05:09 AM
Undefined variable - by El Forum - 02-11-2009, 05:16 AM
Undefined variable - by El Forum - 02-11-2009, 05:17 AM
Undefined variable - by El Forum - 02-11-2009, 05:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB