473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to define variables and avoid Undefined Variable errors?


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
3 7992
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
>>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
>>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stefan Mueller | last post by:
I'm trying to write a PHP script which allows to enter an username and a password and to click two buttons. If I start my PHP scripts 'mytest.php' I see the two input fields and the two buttons....
4
by: Daniel | last post by:
Hullo =) Inspired by another guy's questions here I've created an isset function that works (almost) like the one in native PHP: function isset(variablename) {...
97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
6
by: David T. Ashley | last post by:
Hi, In my project, I typically declare and define variables in the .H file, i.e. DECMOD_MAIN UINT8 can_message_201_status_global #ifdef MODULE_MAIN = HAS_NEVER_BEEN_RECEIVED #endif ;
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
6
by: Clausfor | last post by:
Hello, I have a problem with restoring variables in the setjmp/longjmp functions: K&R2 for longjmp says: "Accessible objects have the same value they had when longjmp was called, except for...
10
by: athanasios.silis | last post by:
Hello everyone, i am attempting to make a structure #include "globalVars.h" struct myStruct{ int offset; unsigned char uChars; } saveVars, getVars;
5
by: MoslyChang | last post by:
Hi, All When I look at effective c++,item2 and item3. I have some basic questions , Does anyone be familar with this topic? it suggests const is perfer to #define, then I think how to replace...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.