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

Posted by Oliver Grδtz on 10/16/49 11:32

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация