You are here: Re: [PHP] Re: php5 call by refference « PHP « IT news, forums, messages
Re: [PHP] Re: php5 call by refference

Posted by Georgi Ivanov on 09/29/48 11:32

Thanks !
It's all clear now .
:)


On Monday 21 November 2005 14:45, Oliver Grätz wrote:
> Georgi Ivanov schrieb:
> > Hi,
> > AFAIK, in PHP5 one can't call function with function parameters .
> > The error is that you only can pass variables by reference.
> > foo(strlen('aaa'),strlen('bbbb'));
> >
> > Is there some sort of workaround ?
>
> First of all, the problem with this arises if your function foo is
> defined as
>
> function foo(&$a,&$b) { ... }
>
> There is no problem if a and b are not reference parameters.
> So think a second about this: You tell in the definition of foo that you
> want to write to the position where a and b are stored. But by calling
> the funtion with strlen() you don't have a position in user space
> because the results of strlen() are just values which haven't been
> explicitly stored.
>
> Now you can decide if you don't write to your parameters a and b. Then
> there is no need for call by reference! It is not true that PHP copies
> the value and that you save memory by using references! The values of
> call-by-value parameters are copied if and only if you WRITE to them!
> The Zend Engine 2 is highly optimized for this.
>
> If you want to write to a and/or b then you must supply a storage
> container (also called variable *g*). Simplest way of supplying a
> temporary container:
>
> foo($t1=strlen('aaa'),$t2=strlen('bbbb'));
>
> Have Fun!
> OLLi

 

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

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