更新时间:2023-11-19 17:31:04
已多次将此行为报告为错误:
This behavior has been reported as a bug a couple times:
我不清楚讨论的结果是什么,尽管这似乎与按值"和按引用"传递值有关.我在一些类似的代码中找到的解决方案做了一些事情像这样:
It is unclear to me what the result of the discussions was although it appears to have something to do with values being passed "by value" and "by reference". A solution that I found in some similar code did something like this:
function &__get( $index )
{
if( array_key_exists( $index, self::$_array ) )
{
return self::$_array[ $index ];
}
return;
}
function &__set( $index, $value )
{
if( !empty($index) )
{
if( is_object( $value ) || is_array( $value) )
{
self::$_array[ $index ] =& $value;
}
else
{
self::$_array[ $index ] =& $value;
}
}
}
请注意它们如何使用&__get
和&__set
,以及在分配值时使用& $value
.我认为这是使这项工作有效的方法.
Notice how they use &__get
and &__set
and also when assigning the value use & $value
. I think that is the way to make this work.