[Solar-talk] Solar_Struct
Paul M Jones
pmjones at solarphp.com
Thu Jul 20 09:08:24 PDT 2006
Hi all,
Regarding Antti's problem with Solar_Struct, it looks like asking for
a struct key using array notation *will not* work in a foreach()
call. This may be related to the following bug reports:
http://bugs.php.net/bug.php?id=34783
http://bugs.php.net/bug.php?id=32983
However, getting a struct key using object notation in a foreach()
*does* work. See attached script (requires SVN version of
Solar_Struct).
To describe in detail, this works as expected:
// key 'foo' is an array or struct
foreach ($struct->foo as $key => $val) {
echo "$key = $val\n";
}
And so does this:
// key 'foo' is an array or struct
$list = $struct['foo'];
foreach ($list as $key => $val) {
echo "$key = $val\n";
}
But this raises a fatal error:
// key 'foo' is an array or struct
foreach ($struct['foo'] as $key => $val) {
echo "$key = $val\n";
}
// Fatal error: Objects used as arrays in post/pre
// increment/decrement must return values by reference
So it looks like the error is related to the foreach() call, maybe
something to do with combining Iterator and ArrayAccess.
I know this may not be in line with expectations (i.e., "struct works
just like an array in most cases"). I guess this is not one of "most
cases."
I am going to report this as a new bug with PHP and see what happens,
but I don't have a good solution for it in the mean time. If anyone
else here can think of anything let me know. Very sorry about this. :-(
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Solar_Struct__test.php
Type: text/php
Size: 919 bytes
Desc: not available
Url : http://mail.killersoft.com/pipermail/solar-talk/attachments/20060720/573c877f/attachment.bin
-------------- next part --------------
More information about the solar-talk
mailing list