RE: [PHP] Accessing the values of objects
| From: | Michael Sims | Date: | Mon, 10 May 2004 19:28:01 +0000 |
| Subject: | RE: [PHP] Accessing the values of objects | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185840@lists.php.net to get a copy of this message | ||
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?