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

Posted by Colin McKinnon on 08/03/06 21:05

jamiesonhale@gmail.com wrote:

> 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 think that a better solution would be to work with the array keys.

But doesn't this work:

function & getAttribute($name)
{
return $this->attributes[$name];
}

For an inelegant hack:
function &getAttribute($name)
{
static $dummy;
$dummy=NULL;
return (isset($this->attributes[$name]) ?
$this->attributes[$name]
: $dummy);
}

C.

 

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

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