2

When I do a print_r on a php variable I get this. This is for a web application i'm working on.

AMC Object
(
 [Player] => AMC_Player Object
    (
        [sourceObj:AMC_Player:private] => AMC Object
 *RECURSION*
        [videoList:AMC_Player:private] => Array
            (
                [0] => 33599
                [1] => 27922
                [3] => 33640
                [4] => 27919
                [5] => 33142
                [6] => 32343
                [7] => 33143
                [8] => 31437
                [9] => 27021
                [10] => 28157
                [11] => 29719
                [12] => 28142
                [13] => 18482
                [15] => 33794
                [16] => 33079
                [17] => 33799
                [18] => 28154
                [19] => 33104
                [20] => 28010
                [21] => 28398
            )

        [videoId:AMC_Player:private] => 
        [artistId:AMC_Player:private] => 
        [userId:AMC_Player:private] => 
        [userName:AMC_Player:private] => 
        [is_songpitches:AMC_Player:private] => 
    )

)

I'm attemping to get the values out of the videoList private variable.

How can this be accomplished?

4
  • 1
    It's a private variable, you can't directly access it, you need a getter for that. (I'm assuming you're using php5?) Commented Dec 21, 2011 at 17:51
  • Does AMC_Player class has any getters ? Commented Dec 21, 2011 at 17:51
  • You would need to check the class itself for getters and look for getters or check the class documentation if any is available. Commented Dec 21, 2011 at 17:56
  • I'll need to check it out. I'm sure it has getters. Commented Dec 21, 2011 at 17:57

1 Answer 1

1

Have a get function in the Player class

class Player{
    ...

    function getVideoList()
    {
        return $this->videoList;
    }
}

And also a get function in the AMC class

function getPlayVidList()
{
     return $this->AMC_Player->getVideoList();
}

$myVidList = $AMC->getPlayVidList();

Sign up to request clarification or add additional context in comments.

4 Comments

If you didn't define these classes, maybe the getter functions are already there. GL
You've got the right idea. Trying to incorporate. The entire AMC class object gets created like this. $GLOBALS['AMC'] = AMC::getInstance(); does it change anything?
the print_r of the variable above comes from GLOBALS['AMC']
@user719316 That doesn't change anything. It is just getting the instance of the class and storing it as a global. I don't know of a way to echo the methods of an object, but if there are any manuals for the library you're using I would take a look at those, or go into the source code itself if you can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.