SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    basic, easy question about returning function values

    I have this class I'm working on (in cakephp), with a function that returns a value.

    PHP Code:
    class KA extends Object {
        function 
    getInfo($username) {
                   
    // do stuff
            
    return $info;
        }

    Ok, so then in my output file I have this:

    PHP Code:
    <?php
    uses
    ('ka');
    KA::getInfo('someuser');
    ?>
    My question - how do I retrieve what's in that $info value in the function? It's supposed to return $info but when I call it, then try to print_r($info) (it's an array of values actually), I get undefined variable errors. If I put print_r($info) in the function itself, I get the array of information. But when I put print_r($info) in the output file, nothing is there. It should be a returned value though, right?

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     
    $arr 
    KA::getInfo('someuser');
    print_r($arr);
     
    // or, simply:
     
    print_r(KA::getInfo('someuser'); 
    This manual page should be helpful, as well as this one.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Location
    New York
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure about return value.. but got a simple work around for you if your array contains strings Use implode() and explode() functions.
    www.forkaya.com - Web Development, PHP Scripting

  4. #4
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ohhhh goes off:

    thanks


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
  •