global variable problem with functions

06-24-07, 08:54 PM
|
|
Newbie Coder
|
|
Join Date: Sep 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
global variable problem with functions
Hi,
I am writing some code, and I am having a problem, and after some checking the issue is as follows:
I have a variable that is declared in a file, lets say file1.php.
Now in my lib.php, i include "file1.php" at the top, and lib.php consists of several functions.
When i use any of the functions in lib.php, they are, for some reason, not in the scope of the variable declared in file1.php.
I even tried declaring the variable as a global variable and it did not work.
The only resolution i could find was passing the variable as a parameter, and that works, but i can not do that in my situation, and need to get it working the other way
any help is appreciated!!
|

06-24-07, 09:27 PM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You would need to post your code to get specific help with it.
100 different people could write 100 differently coded ways to accomplish the same task. Something specific with the code you wrote is preventing the variables from working and no one could possibly know what you have written unless you post your code.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|

06-25-07, 12:28 AM
|
|
Wannabe Coder
|
|
Join Date: Nov 2003
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
__________________
Find me at WHT
|

06-25-07, 02:51 AM
|
|
Newbie Coder
|
|
Join Date: Feb 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
fyre - that's exactly what the issue is (I'm dan man's partner, and we're having that problem)
if anyone could provide some input, that'd be great.
thanks
|

06-25-07, 08:20 AM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Read my post above.
Mind reading does not work over the Internet. Something you are specifically doing or not doing in your code is causing the problem. There could be any number of reasons why this is not working and the only way to get help with the exact problem is if you post your code, otherwise this will just be a game of twenty questions and guesses for answers.
Here are my guesses -
One or more include() statements are failing because the file path is incorrect.
The order of the include() statements are such that the variable does not exist at the time the function call is executed.
The variable(s) are being overwritten by an assignment statement "=" instead of a comparison operator "==".
Typo's in the code.
A problem with register global variables overwriting variables by the same name.
"I even tried declaring the variable as a global variable and it did not work." - Because this was something that was tried after the fact and not already present in the code, it shows that variable scope was not being handled correctly and the global declaration was probably done incorrectly. But we don't know if this was done correctly or not because no code has been posted.
To provide someone with the big picture of what your code is actually doing and to get the quickest solution for your problem, post your code.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|

06-25-07, 03:19 PM
|
|
Newbie Coder
|
|
Join Date: Feb 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mab, there's no reason to post all of our code. Our code is long and many parts, and we'd rather not share it all.
what fyrestrstr posted is exactly the issue we're having. The only difference is, in file1 the variable should be an object, not just a string. But besides that, that's the issue we're having.
|

06-25-07, 10:18 PM
|
|
Newbie Coder
|
|
Join Date: Feb 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
anyways, got it working. I just realized fyrsrstr had actually posted a solution (I thought he was just showing what my problem was by writing the code test for the board)
Last edited by csmaster2005; 06-25-07 at 10:40 PM.
|

06-26-07, 01:43 AM
|
 |
Code Guru
|
|
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by csmaster2005
mab, there's no reason to post all of our code. Our code is long and many parts, and we'd rather not share it all.
|
I could not disagree with you more on this... I know you want to protect your code but at the same time what you said is the equivalent of me going up to a contractor who did not build my house and saying, "um yeah... in my house the pipes are making a souuunnnd or something..., got a solution? Then when he asks to have a look I say no, it's my house I don't want you in it.
At least next time blind fold map and walk him to the part of your house where the pipes are making the noise, let him have a look at the part of the code that is causing you a problem if you wanted a quick answer IMHO.
Glad you found your answer though =)
<3
__________________
"BTW, I can't program at all the only thing I figured out is how to upload templates to my server."
|

06-26-07, 09:33 PM
|
|
Newbie Coder
|
|
Join Date: Feb 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
heh Nova, I understand what you mean, but I did explain exactly what the issue was, and the first post did figure it out
Anyways, thanks alot for the help, and in the future, I'll post actual code examples, that way you dont have to translate my english into code.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|