|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-09 09:32 UTC] ante at novisplet dot com
Description:
------------
If I have an array like this:
ArrayObject Object
(
[group] => Document_Group Object
(
[_dbat] => 0
[_table] => document_group
[_tableat] => document_group
[_where] =>
[_saved] => 1
[_lasterr] =>
[_original] => Array
(
[0] => 1
[1] => skupina 1
)
[group_id] => 1
[name] => skupina 1
)
[documents] => ArrayObject Object
(
[0] => Document Object
(
[_dbat] => 0
[_table] => document
[_tableat] => document
[_where] =>
[_saved] => 1
[_lasterr] =>
[_original] => Array
(
[0] => 1
[1] => Dokument 1
[2] =>
[3] => 1
)
[document_id] => 1
[name] => Dokument 1
[path] =>
[group_id] => 1
)
[1] => Document Object
(
[_dbat] => 0
[_table] => document
[_tableat] => document
[_where] =>
[_saved] => 1
[_lasterr] =>
[_original] => Array
(
[0] => 3
[1] => Dokument 3
[2] =>
[3] => 1
)
[document_id] => 3
[name] => Dokument 3
[path] =>
[group_id] => 1
)
[2] => Document Object
(
[_dbat] => 0
[_table] => document
[_tableat] => document
[_where] =>
[_saved] => 1
[_lasterr] =>
[_original] => Array
(
[0] => 5
[1] => Dokument 5
[2] =>
[3] => 1
)
[document_id] => 5
[name] => Dokument 5
[path] =>
[group_id] => 1
)
)
)
And if I want to access group name the path would be
$array->group->name
but it doesn't work...
I have to use "old style"
$array['group']->name
to get group name...
Reproduce code:
---------------
See description...
Expected result:
----------------
Name of the group to be in
$array->group->name
Actual result:
--------------
but it is in
$array['group']->name
Although everything is "ArrayObject"-ed...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 17:00:01 2025 UTC |
<?php function print_pre($text, $ret = false) { $return = "<pre>" . print_r($text, true) . "</pre>"; if($ret) return $return; print($return); } $array = new ArrayObject(); $node1 = new ArrayObject(); $node2 = new ArrayObject(); $group = new stdClass(); $group->name = "test name"; $group->group_id = 10; $documents = new ArrayObject(); $document1 = new stdClass(); $document1->name = "Document name"; $document1->group_id = 10; $documents->append($document1); $documents->append($document1); $node1->offsetSet("group", $group); $node1->offsetSet("documents", $documents); $node2->offsetSet("group", $group); $node2->offsetSet("documents", $documents); $array->append($node1); $array->append($node2); //print_pre($array); //doesn't work foreach($array as $node) { print($node->group->name); } //works foreach($array as $node) { print($node['group']->name); } ?>