Results 1 to 3 of 3

Thread: _POST, _GET & Classes

  1. #1
    Join Date
    Nov 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default _POST, _GET & Classes

    Is it possible to put _POST or _GET vars in a php 4+ class ??


    if I had
    Code:
    class MyPost{
      
      function MyPost(){
        foreach ($_POST as $k => $v) $this->$k = $v;
      }
    
    }
    I realize the above does not work, just wondering how to fix it.

  2. #2
    Join Date
    Nov 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Solved it.


    Code:
    class MyPost{
      
      function MyPost(){
        foreach ($_POST as $k => $v) $this->{$k} = $v;
        # reminder you can also use $_GET & $_COOKIE instead of $_POST
      }
    
    }

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I see no real reason that wouldn't work. $_GET and $_POST are "autoglobals:" that is to say, they should be automatically defined in any function whose creation results from that request.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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