|
-
Oct 1st, 2002, 12:53 PM
#1
Thread Starter
Addicted Member
Declared var in php page cannot be seen in function ?
Probably an easy problem, but can't figure it out for some reasons !
I have a PHP page in hich i declared a var called $strAction. Now, this var can't be seen in a function of this page (well, it should be visible as a global scope for this page, no ?).
Anyway here's the code :
PHP Code:
$strAction = '';
function IsEnabled()
{
if( $strAction == 'lookup' || $strAction == 'delete') // Line X
return ' disabled ';
else
return '';
}
...
Notice: Undefined variable: strAction in page.php on line X
-
Oct 1st, 2002, 01:16 PM
#2
I've only had limited experience w/ PHP, but... the experience I do have has taught me that unless you explicitly create the variable as global, it's only going to be visible within it's section. In my case, I had a variable in some PHP code, then some straight HTML, followed by a second PHP code section where I tried to use the variable. IT choked in the second sectioon when I tried to use the variable. When I declared it as global, it began working fine.... go figure.... try it and see what happens. Can't hurt.
-
Oct 1st, 2002, 02:28 PM
#3
Frenzied Member
That error is actually only an annoying notice. You can either modify the php.ini file or disable it through the code. In the php.ini file look for the line:
error_reporting = E_ALL & ~E_NOTICE
an uncomment it. Comment all the others.
From within the code:
PHP Code:
error_reporting(E_ALL & ~E_USER_NOTICE);
-
Oct 2nd, 2002, 08:30 AM
#4
Stuck in the 80s
Try this:
Code:
$strAction = '';
function IsEnabled() {
global $strAction;
if( $strAction == 'lookup' || $strAction == 'delete') // Line X
return ' disabled ';
else
return '';
}
-
Oct 2nd, 2002, 09:17 AM
#5
Thread Starter
Addicted Member
Thanks for the help !
Seems to work ok now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|