The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cPanel/WHM API help

Discussion in 'General Discussion' started by webadpro, Feb 26, 2006.

  1. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I was just wondering, can you run a string in a function or does it has to be standalone.

    I'm using whmreq function.

    What I mean extactly is this:

    If I write my coding and at the end I add:

    $bob = $test->adding($host,$user,$accesshash);

    It runs adding and adds the package, like it suppose to do,
    but if I add that line in a function... nothin works.

    Please help,
    I'm in big need.

    Regards,
    Pat
     
  2. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Two words .... "variable scope"
     
  3. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Could you explain a bit more please!?

    Regards,
    Pat
     
  4. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    any more help?
     
  5. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    The function doesn't have access to the variables $test, $host, $user, and $accesshash etc.

    You can use the global keyword to get the vars from the global scope

    PHP:
    <?
    function 
    xxx(){
    global 
    $test$host$user$accesshash;
    $bob $test->adding($host,$user,$accesshash);

    }
    ?>

    or pass in the vars as arguments to the function:
    PHP:
    <?
    function 
    xxx($test$host$user$accesshash){
    $bob $test->adding($host,$user,$accesshash);

    }
    ?>
    But you should read up on your variable scope. It's a basic part of programming PHP.
     
  6. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Thanks Everyone!

    It's finally Working!

    BIG THANKS!
     
    #6 webadpro, Mar 2, 2006
    Last edited: Mar 2, 2006
Loading...

Share This Page