Re: Accessing the values of objects

From: Date: Mon, 10 May 2004 20:04:59 +0000
Subject: Re: Accessing the values of objects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185848@lists.php.net to get a copy of this message
Michael Sims wrote:
John Nichel wrote:
Michael Sims wrote:
John Nichel wrote: Are you sure $bob is an object? It says above that it's an array. If $bob were an object, print_r() should give "objectname Object" instead of "Array".
Nah, that's just my bad typing without thinking. When I print_r($bob), it does start.... bob Object
Well, in that case let me address your original post: John Nichel wrote:
Now, I want to retrive the value of $bob->_four->gamma->word, but how? I've tried $bob->_four->gamma->word, $bob->_four['gamma']['word'],
That last one ($bob->_four['gamma']['word']) should work. It does here. This test script: ---begin quote--- class bob { var $one; var $two; var $three; var $_four; function bob() {
    $this->one   = 'this';
    $this->two   = 'that';
    $this->three = array('alpha' => 'something');
    $this->_four = array(
      'beta'  => 'another',
      'gamma' => array('word' => 'up')
    );
} } $bob = new bob; print_r($bob); print $bob->_four['gamma']['word']."\n"; ----end quote---- prints: ---begin quote--- bob Object (
    [one] => this
    [two] => that
    [three] => Array
        (
            [alpha] => something
        )
    [_four] => Array
        (
            [beta] => another
            [gamma] => Array
                (
                    [word] => up
                )
        )
) up ----end quote---- Do you get different results?
Yeah, I get an empty value for the object I'm working with (quite a bit bigger than the example I posted) when I try to retrive the individual value, but the print_r of the object shows that it has value. I thought my syntax was wrong, but I guess I have to keep digging to find out where the 'trouble' is. Thanks for the help. Aaargh, I hate going behind other people. >:-( -- John C. Nichel KegWorks.com 716.856.9675 john@kegworks.com

« previous php.general (#185848) next »