Garvin Hicking schrieb:
Hi!
It surprises me that this has ever worked :)
it is more than logical that this should work, as = is always evaluated first!
Yes. But NOT if the function parameter expects a REFERENCE variable.
why?
function myFunction(&$param) {}
myFunction($param = true);
this gives the reference $param to the function, there is no reason why this should not work! true is assigned to $param and than $param is passed by reference to the function.
why?
whats the difference between
function( anotherFunction() ); function( $var = 'value' );
???
The difference is that
preg_replace($string, $what, resultArray());
will also not work. You can't/shouldn't pass a function as a referenced variable because of corruption issues that in the past of PHP have lead to problems, which are now being fixed up in recent PHP versions.
yes of course, but it doesn't passes a function, it passes a variable!
what do you think is easier to read? and why should this not work in PHP?
I consider it good coding style to not obfuscate function calls.
yes of course thats why variables names are descriptive
sort_array($my_array);
everything is clear, but
db_close(true, false);
is obfuscated!
so i would prefer
db_close($clean_cache = true, $unset_global_link_variable = false);
...
whatever, i still think this is a php bug!
Sebastian Mendel schrieb:
whatever, i still think this is a php bug!
and it is a undocumented BC-break - whether it should have worked in the past or not (what I'm still thinking is not right, there is no reason why this should not work!)
p.s. but i don't will file a bug personally, i don't like the php 'kernel' community! (they are more than a little bit aloof/overbearing/snotty)
Hi!
why?
function myFunction(&$param) {}
myFunction($param = true);
this gives the reference $param to the function, there is no reason why this should not work! true is assigned to $param and than $param is passed by reference to the function.
Did you test this with PHP 5.1.2?
Please ask on bugs.php.net then for this, but I am quite sure that if it does not work, it's because of the reasons I outlined. Passing assignment values to a function as a REFERENCE variable is methodically problematic, because the parser should/would expect a plain variable there.
yes of course, but it doesn't passes a function, it passes a variable!
That depends on the mechanism of the ZEND Parser and Tokenizer, what is evaluated and passed...so this behaviour might have well been changed in recent PHP5. That's all I'm trying to say. :-)
yes of course thats why variables names are descriptive
sort_array($my_array);
everything is clear, but
db_close(true, false);
is obfuscated!
so i would prefer
db_close($clean_cache = true, $unset_global_link_variable = false);
But this style is actually very rarely used in what I've seen so far, and usually it's up to the IDE (like eclipse) to show you the function parameters for a function call. The way of calling it like above is a larger parsing overhead plus a larger code signature plus more memory usage for variable assignment...
whatever, i still think this is a php bug!
That's not for me to decide, I just tried to point out that such function calls are a bit weird. ;-)
Best regards, Garvin