You are here: Returning a null reference in PHP 4.4.2 « PHP Programming Language « IT news, forums, messages
Returning a null reference in PHP 4.4.2

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация