Closed Thread Icon

Topic awaiting preservation: global variables - PHP (Page 1 of 1) Pages that link to <a href="" title="Pages that link to Topic awaiting preservation: global variables - PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: global variables - PHP <span class="small">(Page 1 of 1)</span>\

Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 12-29-2001 22:57

I have a script with several variables and i want to set the default setting:

if (!$blabla) { $blabla = 15; }

Now i get the following error-message: Warning: Undefined variable: blabla in....

How can i set the default setting to a variable that is undefined? The variable must be changeable in the script and the file reloads themself with the new setting.

Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 12-29-2001 23:03

To save code i would write:

if (!$blabla) $blabla=15;

Other than that I don't know why it is not working. That should check how you are looking for it to check. Maybe it is something in the setup options. Other than that I would not know what to tell you, it looks correct to me.

Off the top of my head if that is not working you could try:

if ($blabla) { /* Do nothing */}
else $blabla = 15;

Not sure. Try maybe it would work.

Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 12-29-2001 23:12

Did not work...
I think it is about the following setting:

- register_globals = Off [Security, Performance]
Global variables are no longer registered for input data (POST, GET, cookies,
environment and other server variables). Instead of using $foo, you must use
you can use $_REQUEST["foo"] (includes any variable that arrives through the
request, namely, POST, GET and cookie variables), or use one of the specific
$_GET["foo"], $_POST["foo"], $_COOKIE["foo"] or $_FILES["foo"], depending
on where the input originates. Also, you can look at the
import_request_variables() function.
Note that register_globals is going to be depracated (i.e., turned off by
default) in the next version of PHP, because it often leads to security bugs.
Read for further

(from the php.ini - recommend file)

Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-29-2001 23:48

I've had this problem on windows platforms but not on *nix

to get around this you can use the isset function

if (!(isset($blabla)) do this.

:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 01-04-2002 13:18

as bitdamaged, said, you can use the isset(), i have made a handy function that tests if set and if empty too:

// Isset and not empty?
function issne($var)
if (!is_array($var))
return isset($var) && !empty($var) ? true : false;
$cond = true;
foreach ($var as $key)
$cond = $cond && isset($key) && !empty($key);
return $cond ? 1 : 0;

you can call it as: if (issne(&$myvar)) { echo "welcome $myvar\n";}
you can test several variables as:
if (issne(array(&$var1, &$var2, &$var3)) { echo 'all variables are set!';}

also, if you don't want to touch your code, you can avoid this warning by adjusting the error reporting level:
error_reporting() usually, i use the E_ALL flag when developing, then turn only the E_ERROR and E_PARSE...

« BackwardsOnwards »

Show Forum Drop Down Menu