|
Posted by jamiesonhale on 08/03/06 20:53
Consider a class that encapsulates an associative array. It has two
"setter" methods:
class A
{
....
function setAttribute( $name, $value )
{
$this->attributes[ $name ] = $value;
}
....
function setAttributeByRef( $name, &$value )
{
$this->attributes[ $name ] =& $value;
}
....
The following "getter" method *used* to work just fine prior to version
4.4.2:
....
function & getAttribute( $name )
{
if ( isset( $this->attributes[ $name ] ) )
return $this->attributes[ $name ];
return NULL;
}
....
However, as of version 4.4.2, this throws a "FATAL: Only variable
references should be returned by reference." error. Unfortunately, my
host (and several of my client hosts) are stuck on this version.
Is there an elegant way to solve this problem? I want to return a value
indicating that no such attribute exists.
(I've googled the problem and can't find anything useful other than a
suggestion in a PHP bug report that I learn how to write "proper"
code.)
Thanks!
J
Navigation:
[Reply to this message]
|