You are here: Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0 « PHP « IT news, forums, messages
Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

Posted by Jochem Maas on 09/20/05 13:40

Jasper Bryant-Greene wrote:
> Jochem Maas wrote:
>
>> Jasper Bryant-Greene wrote:
>>
>>> From the PHP manual [2]:
>>> | the following examples of passing by reference are invalid:
>>> |
>>> | foo(bar()); // Produces fatal error since PHP 5.1.0
>>> | foo($a = 5); // Expression, not variable
>>
>>
>> if foo() expects one args by reference then why is doing:
>>
>> foo($a = 5);
>>
>> ..wrong? I always thought that the expression (in this form) 'returns'
>> the variable? or does it need to be:?
>
>
> Yes, but how can you modify "$a = 5" from within foo()? It's an
> expression, not something that can be modified. This one is, admittedly,

by definition the expression is evaluated _before_ the function is
called - so the expression is not passed to the function, the result
of the expression is passed ... I was under the impression that the the
expression evaluates to a 'pointer' (I'm sure thats bad terminology) to
$a ... which can taken by reference by the function.

possibly I am completely misunderstanding what goes on here.

> kinda shaky.
>
>> I can understand that the following are wrong:
>>
>> foo(5); // not sure this is wrong.
>
>
> This is definitely wrong. For example:

your example make it clear, thanks!

>
> <?php
> function foo(&$a) {
> $a = 6;
> }
>
> foo(5);
> ?>
>
> Is obviously impossible, as it tries to assign the value 6 to the
> constant value 5.
>

 

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

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