Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Weird: $PHP_SELF not working inside function

Options
  • 18-08-2004 5:32pm
    #1
    Registered Users Posts: 912 ✭✭✭


    Hi

    I have a function in which I wish to compare a filename against $PHP_SELF but I can't seem to reference $PHP_SELF from inside the function

    eg. A trimmed down example

    [PHP] <?
    function show_this_page() {
    echo("PHP_SELF from inside function =".$PHP_SELF."<br><br>");
    }
    show_this_page();

    echo("PHP_SELF from outside function =".$PHP_SELF."<br><br>");

    ?> [/PHP]

    is returning
    PHP_SELF from inside function =

    PHP_SELF from outside function =/test.php

    WTF? Many Thanks


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Perhaps you need to pass $PHP_SELF in as an argument?


  • Registered Users Posts: 927 ✭✭✭decob


    i take it your register_globals is turned off..

    use the superglobals, $_SERVER[PHP_SELF]

    [PHP]
    <?
    function show_this_page() {
    echo("PHP_SELF from inside function =".$_SERVER[PHP_SELF]."<br><br>");
    }
    show_this_page();

    echo("PHP_SELF from outside function =".$PHP_SELF."<br><br>");
    ?>
    [/PHP]


  • Registered Users Posts: 912 ✭✭✭chakotha


    Thanks $_SERVER["PHP_SELF"] did it - thought I'd cured myself of those habits!


  • Registered Users Posts: 7,314 ✭✭✭Nietzschean


    <?
    function show_this_page() {
    global $PHP_SELF;
    echo("PHP_SELF from inside function =".$PHP_SELF."<br><br>");
    }
    show_this_page();

    echo("PHP_SELF from outside function =".$PHP_SELF."<br><br>");

    ?>


    No global var's are accessable within functions in PHP, so you must declare them as such.

    Also if you wanted to create a new global variable within the function you would use
    global $MY_VAR = "bleh";

    using it with any assignment basically just imports it into the function though.


Advertisement