You are here: Re: References « PHP Programming Language « IT news, forums, messages
Re: References

Posted by Jerry Stuckle on 05/06/07 15:24

Vince Morgan wrote:
> I guess I don't understand how references work in php;
> Calling a class member function below as an example;
> function &getRow()
> {
> return odbc_fetch_array($this->_det);
> }
> I would expect that I should end up with nothing as there is nothing to
> actualy reference.

But you do have something to reference. odbc_fetch_array returns an
array, and you are returning a reference to that array.

> If I assign the reference as below;
> $var = getRow()
> and then echo the result;
> echo $var['name'];
> echo $var['address'];
> it all works fine, which surprises me somewhat.

No surprise at all. It should work that way.

> In other languages I have more experience with this would throw an error, or
> leave you with a reference to nothing, however in php 5 I can use this
> variable hereon without a problem.

It won't in C++ or Java if odbc_fetch_array returns a reference. It
will work just fine.

> Does php make a copy of the result if there is no var to actualy pass a
> reference to?

All a variable is is a place to keep something to use later. You don't
need to use it again in this function, so there's no need to create a
variable. Just return the array directly, as is being done.

> I can't see how it isn't.
> An explaination of this would be very appreciated.
> TIA,
> Vince
>
>




--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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