#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    187
    Rep Power
    26

    Php variables; oop


    i am trying to call get function call it (getNAME()) in my class file (someClassFile.inc) but i am getting the parameter from the user to call the get function.

    so say,

    $var="get".$_REQUEST['variable']."()";

    $class = new Class();

    print $class->{$var} //will this call my getName() function?

    how can i do it? any takers.

    thanks
    marian
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,971
    Rep Power
    4576
    Should just be $class->$var(). Seems like you're just opening yourself up to security issues if this isn't done correctly and I wonder why you'd even need a hack like this in the first place, but drive on man... drive on.

    ---John Holmes...
    -- Cigars, whiskey and wild, wild women. --
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    187
    Rep Power
    26

    cool


    that works; i can only do it that way because of how the project is.... i know
    thanks though

    cheers
    marian
  6. #4
  7. No Profile Picture
    got Rice?
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Posts
    532
    Rep Power
    15
    Originally Posted by Sepodati
    Should just be $class->$var(). Seems like you're just opening yourself up to security issues if this isn't done correctly and I wonder why you'd even need a hack like this in the first place, but drive on man... drive on.

    ---John Holmes...
    $class->var() ??? shouldnt it be like that? i ran into an issue if doing it with two $ and all. hehe

    Comments on this post

    • stevemchey disagrees : (0) The OP states that she wants to dynamically call the class method depending on $var. Therefore, the $class->$var() approach is syntactically correct...

IMN logo majestic logo threadwatch logo seochat tools logo