Re: Execution order of PHP

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

 



Auke van Slooten wrote:
Bob McConnell wrote:
From: Auke van Slooten

In a hobby project I'm relying on the order in which the following
piece
of PHP code is executed:

$client->system->multiCall(
   $client->methodOne(),
   $client->methodTwo()
);

Think about it from the parser's point of view. It has to evaluate
$client->system to determine the parameter list for multiCall(). Then it
has to evaluate those parameters before it can stuff their values into
the stack so it can call the function. But, whether it evaluates the
parameter list left-to-right or vice versa is implementation dependent.
I don't believe you can rely on it always being the same unless you
always use the same interpreter.

I don't mind about the order in which the parameters are evaluated. The only thing that must stay the same for my code to work as designed is that $client->system is evaluated before any of the arguments to the multiCall method. Your explanation seems reasonable to me, but I've been informed by people that know more about parsers and compilers than me, that theoretically there is no requirement for this to be true...

After a further education just now, it is possible for a compiler to parse the entire multiCall right to left, so it will first evaluate $client->methodTwo(), then $client->methodOne() and only then resolves $client->system->multiCall. Before evaluating this call, the compiler can still check whether the number of arguments matches the parameter list of the function definition.

Anyway, the point is that I'd like to be able to write multiCall statements like written above instead of doing something like this:

$client->system->multiCall(
   array( 'method' => 'methodOne',
          'params' => array() ),
   array( 'method' => 'methodTwo',
          'params' => array() )
);

regards,
Auke van Slooten
Muze

I don't understand the point in a 10 message thread to ascertain the safety of what you are doing when you already know it is questionable in practice and that simply breaking the statements into multiple statements with temporary variables will provide a perfectly good solution. The work involved in breaking the code into multiple lines would be a fraction of that contributed to writing to the list. So the question now is... are you just looking to discuss the merits and demerits of implementation dependent processing order or do you want someone to tell you it's ok to write questionable code? Regardless of the point and what you end up doing, I would add a comment in your code explaining that the order of function evaluation is important.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
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