By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,370 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,370 IT Pros & Developers. It's quick & easy.

how to define variables and avoid Undefined Variable errors?

P: n/a

how does one set a variable so as to avoid errors like this:

Notice: Undefined variable: arrayToCapture in
/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/pdsIncludes/McControllerForAll.php
on line 922

Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 20 Jul 2005 14:32:42 -0700, lk******@geocities.com wrote:
how does one set a variable
Using '='.
so as to avoid errors like this:

Notice: Undefined variable: arrayToCapture in
/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/pdsIncludes/McControllerForAll.php
on line 922


Or you can check whether it's defined using isset().

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 21 '05 #2

P: n/a
>>how does one set a variable

Using '='.


So PHP doesn't like using a variable that hasn't first been set:

if (!$notes) {
echo $message;
}
So one should have a line that declares up top, perhaps:


function McResults() {
$notes = false;
global $HTTP_GET_VARS;
if (isset($HTTP_GET_VARS["notes"])) $notes = $HTTP_GET_VARS["notes"];
if (!$notes) {
if (isset($_GET["notes"])) $notes = $_GET["notes"];
}
if (!$notes) {
global $HTTP_POST_VARS;
if (isset($HTTP_POST_VARS["notes"])) $notes =
$HTTP_POST_VARS["notes"];
if (!$notes) {
if (isset($_POST["notes"])) $notes = $_POST["notes"];
}
}
$this->notes = $notes;
}


And having that line up top:

$notes = false;

means that PHP won't complain?

Jul 21 '05 #3

P: n/a
>>so as to avoid errors like this:

Notice: Undefined variable: arrayToCapture in
/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/pdsIncludes/McControllerForAll.php
on line 922


Or you can check whether it's defined using isset().


But then, if I go like this:

$trustThisUser = false;

// some code here, and then:

if (isset($trustThisUser)) {
echo $password;
}
This is quite different from:
if ($trustThisUser) {
echo $password;
}

The first if statement will always be true, which is not what I want.
Am I right about that? I'd need to do something like:

if (isset($trustThisUser)) {
if ($trustThisUser === true) {
echo $password;
}
}

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.