Results 1 to 5 of 5

Thread: Declared var in php page cannot be seen in function ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212

    Question 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 
    '';
    }

    ...

    NoticeUndefined variablestrAction in page.php on line X 
    Regards,

    El-Nino

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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); 

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Try this:

    Code:
    $strAction = '';
    function IsEnabled() {
        global $strAction;
    
        if( $strAction == 'lookup' || $strAction == 'delete') // Line X
            return ' disabled ';
        else
            return '';
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    Thanks for the help !
    Seems to work ok now
    Regards,

    El-Nino

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width