PHP5 and Global Array ($_GET)

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

    PHP5 and Global Array ($_GET)

    I had a client recently contact me with a script that wasn't working. I
    quickly isolated the problem as to the fact that the $_GET array was not
    being made available to all scripts, even though register_global s was set to
    ON. The client then notified his host who seemed to know exactly the issue
    and we added these lines to the top of the script (this script is included
    in all other scripts) and it solved the problems:

    /* mp.net patch */
    foreach($_GET as $var => $value) $$var = $value;
    foreach($_POST as $var => $value) $$var = $value;
    foreach($_COOKI E as $var => $value) $$var = $value;
    foreach($_SERVE R as $var => $value) $$var = $value;
    ob_start();
    /* end of patch */

    The host added these comments to my client:
    "I can fix that for you, but in a couple of months, PHP5 will be out for
    real, so you might as well want to fix it in your code."

    Is this a work-around for right now or is there some kind of rework that all
    scripts will have to be modified for version 5?

    --
    Gaylen
    Raven Web Hosting http://ravenwebhosting.com
    PHP KISGB PHP Guest Book for Standard and phpNuke sites

    PHP KISSQ PHP Stock Quote for Standard and phpNuke sites



  • André Næss

    #2
    Re: PHP5 and Global Array ($_GET)

    gf:
    [color=blue]
    > I had a client recently contact me with a script that wasn't working. I
    > quickly isolated the problem as to the fact that the $_GET array was not
    > being made available to all scripts, even though register_global s was set
    > to
    > ON. The client then notified his host who seemed to know exactly the
    > issue and we added these lines to the top of the script (this script is
    > included in all other scripts) and it solved the problems:
    >
    > /* mp.net patch */
    > foreach($_GET as $var => $value) $$var = $value;
    > foreach($_POST as $var => $value) $$var = $value;
    > foreach($_COOKI E as $var => $value) $$var = $value;
    > foreach($_SERVE R as $var => $value) $$var = $value;
    > ob_start();
    > /* end of patch */[/color]

    // A simpler solution:
    extract($_REQUE ST);
    extract($_SESSI ON);
    [color=blue]
    > The host added these comments to my client:
    > "I can fix that for you, but in a couple of months, PHP5 will be out for
    > real, so you might as well want to fix it in your code."
    >
    > Is this a work-around for right now or is there some kind of rework that
    > all scripts will have to be modified for version 5?[/color]

    register_global s is considered a bad thing, so you should really strive to
    move away from it.

    André Næss

    Comment

    • gf

      #3
      Re: PHP5 and Global Array ($_GET)

      "André Næss" <andrena.spamre allysucks@ifi.u io.no> wrote in message
      news:bnf89a$48b $1@maud.ifi.uio .no...[color=blue]
      > gf:
      >[color=green]
      > > I had a client recently contact me with a script that wasn't working. I
      > > quickly isolated the problem as to the fact that the $_GET array was not
      > > being made available to all scripts, even though register_global s was[/color][/color]
      set[color=blue][color=green]
      > > to
      > > ON. The client then notified his host who seemed to know exactly the
      > > issue and we added these lines to the top of the script (this script is
      > > included in all other scripts) and it solved the problems:
      > >
      > > /* mp.net patch */
      > > foreach($_GET as $var => $value) $$var = $value;
      > > foreach($_POST as $var => $value) $$var = $value;
      > > foreach($_COOKI E as $var => $value) $$var = $value;
      > > foreach($_SERVE R as $var => $value) $$var = $value;
      > > ob_start();
      > > /* end of patch */[/color]
      >
      > // A simpler solution:
      > extract($_REQUE ST);
      > extract($_SESSI ON);
      >[color=green]
      > > The host added these comments to my client:
      > > "I can fix that for you, but in a couple of months, PHP5 will be out for
      > > real, so you might as well want to fix it in your code."
      > >
      > > Is this a work-around for right now or is there some kind of rework that
      > > all scripts will have to be modified for version 5?[/color]
      >
      > register_global s is considered a bad thing, so you should really strive to
      > move away from it.
      >
      > André Næss[/color]


      That's not the point, though, although I understand. This is not my
      application and the application requires it.

      Can anyone address my original question?

      Gaylen
      Raven Web Hosting http://ravenwebhosting.com
      PHP KISGB PHP Guest Book for Standard and phpNuke sites

      PHP KISSQ PHP Stock Quote for Standard and phpNuke sites



      Comment

      • John Downey

        #4
        Re: PHP5 and Global Array ($_GET)

        gf wrote:[color=blue][color=green][color=darkred]
        >>>I had a client recently contact me with a script that wasn't working. I
        >>>quickly isolated the problem as to the fact that the $_GET array was not
        >>>being made available to all scripts, even though register_global s was[/color][/color]
        >
        > set
        >[color=green][color=darkred]
        >>>to
        >>>ON.[/color][/color][/color]
        Though I am not sure about PHP5 it might be different but perhaps if
        there were no query string parameters passed like script.php?foo= bar
        then PHP has no need to create and populate a $_GET array. This might be
        a bug where when you include() other files it doesn't see it as the same
        request and carry over the super globals. I don't know I have yet to sit
        down and hammer out code for PHP5 given its still beta. Also I always
        use isset() on a variable if its supplied in _GET/_POST/_COOKIE to make
        sure that its actually there. And again tell your client to stop
        requiring register_global s or they might find themselves left in the
        dust, PHP is still a young language and continues to evolve.

        --
        John Downey




        Comment

        • André Næss

          #5
          Re: PHP5 and Global Array ($_GET)

          gf:
          [color=blue][color=green]
          >> register_global s is considered a bad thing, so you should really strive
          >> to move away from it.[/color][/color]
          [color=blue]
          > That's not the point, though, although I understand. This is not my
          > application and the application requires it.
          >
          > Can anyone address my original question?[/color]

          Ok, I guess what you're wondering is "Will register globals disappear from
          PHP5?". The answer seems to be no, see: http://zend.com/php/ask_experts.php
          (currently fifth question from top).

          André Næss

          Comment

          • gf

            #6
            Re: PHP5 and Global Array ($_GET)

            "John Downey" <blah@doesntexi st.com> wrote in message
            news:%tGmb.1652 13$xx4.29535333 @twister.neo.rr .com...[color=blue]
            > gf wrote:[color=green][color=darkred]
            > >>>I had a client recently contact me with a script that wasn't working.[/color][/color][/color]
            I[color=blue][color=green][color=darkred]
            > >>>quickly isolated the problem as to the fact that the $_GET array was[/color][/color][/color]
            not[color=blue][color=green][color=darkred]
            > >>>being made available to all scripts, even though register_global s was[/color]
            > >
            > > set
            > >[color=darkred]
            > >>>to
            > >>>ON.[/color][/color]
            > Though I am not sure about PHP5 it might be different but perhaps if
            > there were no query string parameters passed like script.php?foo= bar
            > then PHP has no need to create and populate a $_GET array. This might be
            > a bug where when you include() other files it doesn't see it as the same
            > request and carry over the super globals. I don't know I have yet to sit
            > down and hammer out code for PHP5 given its still beta. Also I always
            > use isset() on a variable if its supplied in _GET/_POST/_COOKIE to make
            > sure that its actually there. And again tell your client to stop
            > requiring register_global s or they might find themselves left in the
            > dust, PHP is still a young language and continues to evolve.
            >
            > --
            > John Downey
            > http://delusive.dyn.ee
            > http://sage.dev.box.sk
            > http://blacksun.box.sk
            >[/color]
            They are being passed. This works perfectly on v4.x . There are no issues
            with the way the script is apssing anything. it is directly related to
            something in php5.

            --
            Gaylen
            Raven Web Hosting http://ravenwebhosting.com
            PHP KISGB PHP Guest Book for Standard and phpNuke sites

            PHP KISSQ PHP Stock Quote for Standard and phpNuke sites



            Comment

            Working...