Re: Tidying code for PHP5.0.5/PHP4.4.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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, kinda shaky.

I can understand that the following are wrong:

foo(5); // not sure this is wrong.

This is definitely wrong. For example:

<?php
function foo(&$a) {
	$a = 6;
}

foo(5);
?>

Is obviously impossible, as it tries to assign the value 6 to the constant value 5.

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux