[Phpmyadmin-devel] a PHP 5.1.2 bug?

Sebastian Mendel lists at sebastianmendel.de
Fri Jan 13 06:56:14 CET 2006


Marc Delisle schrieb:
> Sebastian Mendel a écrit :
>> Marc Delisle schrieb:
>>
>>> Sebastian Mendel a écrit :
>>>
>>>> Garvin Hicking schrieb:
>>>>
>>>>
>>>>> Hi Marc!
>>>>>
>>>>>
>>>>>
>>>>>> Look at this sample code:
>>>>>> <?php
>>>>>> $the_query = "INSERT INTO `aaa` (`f1`, `f2`) VALUES ('1', 'aaa')";
>>>>>> preg_match('@INSERT\sINTO\s\`([^\`]+)\`@iu', $the_query,
>>>>>> $error_table = array()
>>>>>> );
>>>>>> print_r($error_table); ?>
>>>>>
>>>>> It surprises me that this has ever worked :)
>>>>
>>>>
>>>> me not!
>>>>
>>>> it is more than logical that this should work, as = is always evaluated
>>>> first!
>>>>
>>>>
>>>>
>>>>
>>>>> I guess that PHP 5.1.2 has a different way of evaluating/processing
>>>>> the order of
>>>>> the array assignment. But the way of specifieing an assignment within
>>>>> a function
>>>>> call is something I've never seen before, and also looks a bit
>>>>> misleading-codewise, IMHO.
>>>>>
>>>>> So you might want to ask how this problem came, but I'm pretty sure
>>>>> the answer
>>>>> will be "It was never meant to work, so you shouldn't have relied on
>>>>> it. We
>>>>> fixed this because of memory corruption issues" ;-)
>>>>
>>>>
>>>> i don't think so.
>>>>
>>>> why?
>>>>
>>>> whats the difference between
>>>>
>>>> function( anotherFunction() );
>>>> function( $var = 'value' );
>>>>
>>>> ???
>>>>
>>>> why should this not work?
>>>>
>>>> for example in C i often see this to clarify parameters
>>>>
>>>> function(true, false, true);
>>>> or
>>>> function($use_utf8 = true, $return = false, $escape = true);
>>>>
>>>> what do you think is easier to read? and why should this not work in
>>>> PHP?
>>>>
>>>>
>>>
>>> Hi Sebastian,
>>>
>>> Please do not draw too general conclusions about what I wrote. This
>>> example works in PHP 5.1.2:
>>>
>>> $error_table = array();
>>>
>>> preg_match('@INSERT\sINTO\s\`([^\`]+)\`@iu',
>>>  $the_query =  "INSERT INTO `aaa` (`f1`, `f2`) VALUES ('1', 'aaa')", 
>>> $error_table );
>>>
>>> print_r($error_table);
>>> ?>
>>
>>
>> of course not!
> 
> What do you mean "of course not"? That this script does not work?

no

> It works in PHP 5.1.2.

yes,

of course not, i don't take too general conclusions about what you wrote!


>>> I was just talking about using
>>> $error_table = array()
>>> as a function argument.

yes, me too!


>>> Anyway, I could not find this syntax in the doc. If you can't find it in
>>> the doc either, then this would be a PHP feature request :)
>>
>>
>> the problem is not that this variable is not assigned in the function
>> call, but it is assigned AFTER the function is executed:
>>
>> <?php
>> function myFunc(&$var)
>> {
>>     $var = 'set in function';
>> }
>>
>> $var = 'set before function';
>> myFunc($var = 'set in function call');
>>
>> var_dump($var);
>> ?>
>>
>> expected, and how it was before 5.1.2:
>> set in function
>>
>> now with 5.1.2 it prints:
>> set in function call
>
> Again, where do you see in the doc that we are allowed to do this?

the documentation writes with examples what can be done, but not ALL
what can be done!

it seems just logical that expressions evaluated first before passed to
the function - and as you can see in my other mail it is still be done,
but after the call again!

  printLocalDate(time() + 60*60*24 * 12); // current time plus 12 days

why should this not work? there is no need to assign this value first to
a variable and than pass this variable to the function

and

  myFunc($var = 'value');

is not much different, or?


-- 
Sebastian Mendel

www.sebastianmendel.de
www.sf.net/projects/phpdatetime | www.sf.net/projects/phptimesheet




More information about the Developers mailing list