Accessing $HTTP_GET_VARS in classes..?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Hall

    Accessing $HTTP_GET_VARS in classes..?

    Hey guys,

    I'm building a web application in php for the first time (I like php a
    lot..) and have come across a litle stumbling block.

    I want to access a passed url parameter with $HTTP_GET_VARS in a class, but
    I can't get it to work.

    Note the following php page, which creates an object that pulls the "param"
    parameter in both the class and globally. The global one works, the one in
    the class doesn't.

    I'm sure I'm doing something stupid - any pointers..?

    Thanks,

    ----------------------------------------------------------------------------
    -
    Call the page with "test.php?param =value"
    ----------------------------------------------------------------------------
    -

    <?php
    class oTest
    {
    var $param;

    function oTest()
    {
    $this -> param = $HTTP_GET_VARS["param"];
    }
    }
    ?>
    <html>
    <head>
    </head>
    <body>
    <?php
    $my_instance = new oTest;

    print "From object: " . $my_instance->param . "<br>";
    print "From global: " . $HTTP_GET_VARS["param"];
    ?>
    </body>
    </html>

    --
    Ben Hall



  • Ben Hall

    #2
    Re: Accessing $HTTP_GET_VARS in classes..?

    Ah, figured as soon as I asked for help, I'd fix it...

    I needed to global $HTTP_GET_VARS. .. duh!!

    Thanks anyway... :)

    --
    Ben Hall



    Comment

    • Matthias Esken

      #3
      Re: Accessing $HTTP_GET_VARS in classes..?

      "Ben Hall" <benj@serious ly-productions.fre eserve.co.uk> schrieb:
      [color=blue]
      > I'm building a web application in php for the first time (I like php a
      > lot..) and have come across a litle stumbling block.
      >
      > I want to access a passed url parameter with $HTTP_GET_VARS in a class, but
      > I can't get it to work.ยด[/color]

      Try

      global $HTTP_GET_VARS;

      in the first line of the function. In the PHP documentation at
      http://www.php.net/manual/en/languag...bles.scope.php you'll find
      some more informations.

      Matthias

      Comment

      Working...