Execution order of PHP

Execution order of PHP

am 10.03.2010 14:29:22 von Auke van Slooten

Hi,

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()
);

Currently PHP always resolves $client->system (and executes the __get on
$client) before resolving the arguments to the multiCall() method call.

Is this order something that is specified by PHP and so can be relied
upon to stay the same in the future or is it just how it currently works.

If it cannot be relied upon to stay this way, I will have to rewrite the
multiCall method and API...

regards,
Auke van Slooten
Muze

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

Re: Execution order of PHP

am 10.03.2010 14:37:40 von Bruno Fajardo

2010/3/10 Auke van Slooten
>
> Hi,
>
> In a hobby project I'm relying on the order in which the following piece =
of PHP code is executed:
>
> $client->system->multiCall(
> =A0$client->methodOne(),
> =A0$client->methodTwo()
> );
>
> Currently PHP always resolves $client->system (and executes the __get on =
$client) before resolving the arguments to the multiCall() method call.

Hi!

Can't you call the methods $client->methodOne() and
$client->methodTwo() before the call to $client->system->multiCall()?
That way, you could store they values in local variables, and then
pass them to the $client->system->multiCall(), assuring that those
methods are executed before the multiCall(). Something like:

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

Cheers,
Bruno.

>
> Is this order something that is specified by PHP and so can be relied upo=
n to stay the same in the future or is it just how it currently works.
>
> If it cannot be relied upon to stay this way, I will have to rewrite the =
multiCall method and API...
>
> regards,
> Auke van Slooten
> Muze
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

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

RE: Execution order of PHP

am 10.03.2010 14:41:25 von Bob McConnell

From: Auke van Slooten

> In a hobby project I'm relying on the order in which the following
piece=20
> of PHP code is executed:
>=20
> $client->system->multiCall(
> $client->methodOne(),
> $client->methodTwo()
> );
>=20
> Currently PHP always resolves $client->system (and executes the __get
on=20
> $client) before resolving the arguments to the multiCall() method
call.
>=20
> Is this order something that is specified by PHP and so can be relied=20
> upon to stay the same in the future or is it just how it currently
works.
>=20
> If it cannot be relied upon to stay this way, I will have to rewrite
the=20
> multiCall method and API...

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.

Bob McConnell

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

Re: Execution order of PHP

am 10.03.2010 15:13:00 von Auke van Slooten

Bruno Fajardo wrote:
> 2010/3/10 Auke van Slooten
>> Hi,
>>
>> 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()
>> );
>
> Can't you call the methods $client->methodOne() and
> $client->methodTwo() before the call to $client->system->multiCall()?
> That way, you could store they values in local variables, and then
> pass them to the $client->system->multiCall(), assuring that those
> methods are executed before the multiCall(). Something like:
>
> $methodOne = $client->methodOne();
> $methodTwo = $client->methodTwo();
> $client->system->multiCall($methodOne, $methodTwo);

Hi,

This is not what I meant. I should perhaps mention that it's an xml-rpc
client and the method calls are remote method calls. The multiCall
method gathers multiple method calls into a single request.

The trick I'm using now is to set a private property in the
$client->__get() method when the property you're accessing is 'system'.
From then untill you call the method 'multiCall', instead of calling
the methods (in this case methodOne and methodTwo) the client creates a
new object with the call information (method name and arguments) and
returns that. In multiCall all arguments are therefor call information
objects and multicall creates a single request based on that information.

So in your example the client would simply call methodOne and methodTwo
and return the results. Then it would try to do a multiCall with
whatever the previous methods have returned.

regards,
Auke van Slooten
Muze

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

Re: Execution order of PHP

am 10.03.2010 15:18:22 von Ashley Sheridan

--=-rTg3cW8IcOc2h13AMJxX
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Wed, 2010-03-10 at 15:20 +0100, Sándor Tamás wrote:

>=20
> 2010.03.10. 14:41 keltezéssel, Bob McConnell írta:
> > From: Auke van Slooten
> >
> > =20
> >> In a hobby project I'm relying on the order in which the following
> >> =20
> > piece
> > =20
> >> of PHP code is executed:
> >>
> >> $client->system->multiCall(
> >> $client->methodOne(),
> >> $client->methodTwo()
> >> );
> >>
> >> Currently PHP always resolves $client->system (and executes the __get
> >> =20
> > on
> > =20
> >> $client) before resolving the arguments to the multiCall() method
> >> =20
> > call.
> > =20
> >> Is this order something that is specified by PHP and so can be relied
> >> upon to stay the same in the future or is it just how it currently
> >> =20
> > works.
> > =20
> >> If it cannot be relied upon to stay this way, I will have to rewrite
> >> =20
> > the
> > =20
> >> multiCall method and API...
> >> =20
> > Think about it from the parser's point of view. It has to evaluate
> > $client->system to determine the parameter list for multiCall(). Then i=
t
> > 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.
> >
> > Bob McConnell
> >
> > =20
> I think it cannot be that the evaluation order of the parameters is=20
> implementation dependent.
> Just think about it:
> $someobject->method($a++, $a++);
>=20
> What will be the result? Or there has to be some directive to tell the=20
> parser to evaluate the parameters from left to right or vice versa.
> And if there isn't, in some future release, there has to be.
>=20
> SanTa
>=20


The order is implementation dependent, and just follows from other
languages which behave exactly the same (I believe Java and C++ both do)

This is the sort of example that's used as a reason to not rely on such
behaviour. You just have to work around it I guess.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-rTg3cW8IcOc2h13AMJxX--

Re: Execution order of PHP

am 10.03.2010 15:20:02 von sandortamas

--------------ms070607060200040907020204
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable



2010.03.10. 14:41 keltez=E9ssel, Bob McConnell =EDrta:
> From: Auke van Slooten
>
> =20
>> In a hobby project I'm relying on the order in which the following
>> =20
> piece
> =20
>> of PHP code is executed:
>>
>> $client->system->multiCall(
>> $client->methodOne(),
>> $client->methodTwo()
>> );
>>
>> Currently PHP always resolves $client->system (and executes the __get
>> =20
> on
> =20
>> $client) before resolving the arguments to the multiCall() method
>> =20
> call.
> =20
>> Is this order something that is specified by PHP and so can be relied
>> upon to stay the same in the future or is it just how it currently
>> =20
> works.
> =20
>> If it cannot be relied upon to stay this way, I will have to rewrite
>> =20
> the
> =20
>> multiCall method and API...
>> =20
> Think about it from the parser's point of view. It has to evaluate
> $client->system to determine the parameter list for multiCall(). Then i=
t
> 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.
>
> Bob McConnell
>
> =20
I think it cannot be that the evaluation order of the parameters is=20
implementation dependent.
Just think about it:
$someobject->method($a++, $a++);

What will be the result? Or there has to be some directive to tell the=20
parser to evaluate the parameters from left to right or vice versa.
And if there isn't, in some future release, there has to be.

SanTa


--------------ms070607060200040907020204
Content-Type: application/pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEH AQAAoIIMcDCC
BjQwggUcoAMCAQICEA+FQLvD2rs4hOLLitSNT8AwDQYJKoZIhvcNAQEFBQAw ga4xCzAJBgNV
BAYTAlVTMQswCQYDVQQIEwJVVDEXMBUGA1UEBxMOU2FsdCBMYWtlIENpdHkx HjAcBgNVBAoT
FVRoZSBVU0VSVFJVU1QgTmV0d29yazEhMB8GA1UECxMYaHR0cDovL3d3dy51 c2VydHJ1c3Qu
Y29tMTYwNAYDVQQDEy1VVE4tVVNFUkZpcnN0LUNsaWVudCBBdXRoZW50aWNh dGlvbiBhbmQg
RW1haWwwH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g7mqYRfXZ2Ok7V6pfdM Jy863r8mse/4
ewT50OOWdKiIlh25IZUsD9K+xXWEVghjwLwxLMGExwITFA5vP8T+jhF/y0G4 fkLTUrK1StSP
qfKMlqWs6+dVxSPKqhhBqLRrt9aghy9okZ1P3nqn0pUbLrKXpqW7lEnxEAME 0csKaLPMRoaU
jUxoy+zIITfsBZw+lxYhN4pmL64MaAWzYzhZLuU/c1iTNvzWWAAAAAAAAA==
--------------ms070607060200040907020204--

Re: Execution order of PHP

am 10.03.2010 15:23:43 von Auke van Slooten

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

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

RE: Execution order of PHP

am 10.03.2010 15:37:10 von Bob McConnell

From: S=E1ndor Tam=E1s

> 2010.03.10. 14:41 keltez=E9ssel, Bob McConnell =EDrta:
>> From: Auke van Slooten
>>
>>> In a hobby project I'm relying on the order in which the following
>>> =20
>> piece
>> =20
>>> of PHP code is executed:
>>>
>>> $client->system->multiCall(
>>> $client->methodOne(),
>>> $client->methodTwo()
>>> );
>>>
>>> Currently PHP always resolves $client->system (and executes the =
__get
>>> =20
>> on
>> =20
>>> $client) before resolving the arguments to the multiCall() method
>>> =20
>> call.
>> =20
>>> Is this order something that is specified by PHP and so can be =
relied
>>> upon to stay the same in the future or is it just how it currently
>>> =20
>> works.
>> =20
>>> If it cannot be relied upon to stay this way, I will have to rewrite
>>> =20
>> the
>> =20
>>> multiCall method and API...
>>> =20
>> 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.
> =20
> I think it cannot be that the evaluation order of the parameters is=20
> implementation dependent.
> Just think about it:
> $someobject->method($a++, $a++);
>=20
> What will be the result? Or there has to be some directive to tell the =

> parser to evaluate the parameters from left to right or vice versa.
> And if there isn't, in some future release, there has to be.

The result of that line would be undefined in any language I am familiar =
with. I could manually implement a variation in assembler that would be =
safe, but nowhere else. You have too many operations in a row on a =
single variable without adequate checkpoints between them.

Bob McConnell

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

Re: Execution order of PHP

am 10.03.2010 15:52:24 von Robert Cummings

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

Re: Execution order of PHP

am 10.03.2010 15:54:59 von Bruno Fajardo

2010/3/10 Auke van Slooten :
> Bruno Fajardo wrote:
>>
>> 2010/3/10 Auke van Slooten
>>>
>>> Hi,
>>>
>>> In a hobby project I'm relying on the order in which the following piec=
e
>>> of PHP code is executed:
>>>
>>> $client->system->multiCall(
>>> =A0$client->methodOne(),
>>> =A0$client->methodTwo()
>>> );
>>
>> Can't you call the methods $client->methodOne() and
>> $client->methodTwo() before the call to $client->system->multiCall()?
>> That way, you could store they values in local variables, and then
>> pass them to the $client->system->multiCall(), assuring that those
>> methods are executed before the multiCall(). Something like:
>>
>> $methodOne =3D $client->methodOne();
>> $methodTwo =3D $client->methodTwo();
>> $client->system->multiCall($methodOne, $methodTwo);
>
> Hi,
>
> This is not what I meant. I should perhaps mention that it's an xml-rpc
> client and the method calls are remote method calls. The multiCall method
> gathers multiple method calls into a single request.
>
> The trick I'm using now is to set a private property in the $client->__ge=
t()
> method when the property you're accessing is 'system'. From then untill y=
ou
> call the method 'multiCall', instead of calling the methods (in this case
> methodOne and methodTwo) the client creates a new object with the call
> information (method name and arguments) and returns that. In multiCall al=
l
> arguments are therefor call information objects and multicall creates a
> single request based on that information.

Hmm, you cleared that to me now... If you need to first create the
property "system" and then call a method in that object "system",
can't you do something like:

$client->system =3D null;
$client->system->multiCall(
$client->methodOne(),
$client->methodTwo()
);

I'm not testing these snippets of code, so sorry if I'm getting something w=
rong.

Cheers,
Bruno.

>
> So in your example the client would simply call methodOne and methodTwo a=
nd
> return the results. Then it would try to do a multiCall with whatever the
> previous methods have returned.
>
> regards,
> Auke van Slooten
> Muze
>

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

Re: Execution order of PHP

am 10.03.2010 16:09:50 von Andrew Ballard

On Wed, Mar 10, 2010 at 9:54 AM, Bruno Fajardo wrote:
[snip]
> 2010/3/10 Auke van Slooten :
>> This is not what I meant. I should perhaps mention that it's an xml-rpc
>> client and the method calls are remote method calls. The multiCall metho=
d
>> gathers multiple method calls into a single request.
>>
>> The trick I'm using now is to set a private property in the $client->__g=
et()
>> method when the property you're accessing is 'system'. From then untill =
you
>> call the method 'multiCall', instead of calling the methods (in this cas=
e
>> methodOne and methodTwo) the client creates a new object with the call
>> information (method name and arguments) and returns that. In multiCall a=
ll
>> arguments are therefor call information objects and multicall creates a
>> single request based on that information.
>
> Hmm, you cleared that to me now... If you need to first create the
> property "system" and then call a method in that object "system",
> can't you do something like:
>
> $client->system =3D null;
> $client->system->multiCall(
>    $client->methodOne(),
>    $client->methodTwo()
> );
>
> I'm not testing these snippets of code, so sorry if I'm getting something=
wrong.
>
> Cheers,
> Bruno.
>
[snip]

I'm not sure you would want to assign null to $client->system. After
all, __set() might not be defined.

I agree with Rob here. If order is really crucial, then call the
statements in the correct order:


/**
* causes $client to call __get() in order to resolve
* 'system'
*/
$system =3D $client->system;


/**
* You should add some handling here to make sure that
* $system is really an object that implements your
* multiCall() method, and not something else (like null).
*/


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

?>



Andrew

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

Re: Execution order of PHP

am 10.03.2010 17:07:06 von Bruno Fajardo

2010/3/10 Andrew Ballard :
> On Wed, Mar 10, 2010 at 9:54 AM, Bruno Fajardo wrot=
e:
> [snip]
>> 2010/3/10 Auke van Slooten :
>>> This is not what I meant. I should perhaps mention that it's an xml-rpc
>>> client and the method calls are remote method calls. The multiCall meth=
od
>>> gathers multiple method calls into a single request.
>>>
>>> The trick I'm using now is to set a private property in the $client->__=
get()
>>> method when the property you're accessing is 'system'. From then untill=
you
>>> call the method 'multiCall', instead of calling the methods (in this ca=
se
>>> methodOne and methodTwo) the client creates a new object with the call
>>> information (method name and arguments) and returns that. In multiCall =
all
>>> arguments are therefor call information objects and multicall creates a
>>> single request based on that information.
>>
>> Hmm, you cleared that to me now... If you need to first create the
>> property "system" and then call a method in that object "system",
>> can't you do something like:
>>
>> $client->system =3D null;
>> $client->system->multiCall(
>> =A0 =A0$client->methodOne(),
>> =A0 =A0$client->methodTwo()
>> );
>>
>> I'm not testing these snippets of code, so sorry if I'm getting somethin=
g wrong.
>>
>> Cheers,
>> Bruno.
>>
> [snip]
>
> I'm not sure you would want to assign null to $client->system. After
> all, __set() might not be defined.

Yes, you're right, Andrew. Setting the property to null is not the
best choice in this case.

>
> I agree with Rob here. If order is really crucial, then call the
> statements in the correct order:
>
> >
> /**
> =A0* causes $client to call __get() in order to resolve
> =A0* 'system'
> =A0*/
> $system =3D $client->system;
>

This was my point too, to create the object before the call to
multiCall(), I just messed my example with the null assignment... :-)
The code you suggested must solve the OP issue.

Cheers,
Bruno.

>
> /**
> =A0* You should add some handling here to make sure that
> =A0* $system is really an object that implements your
> =A0* multiCall() method, and not something else (like null).
> =A0*/
>
>
> $system->multiCall(
> =A0 =A0$client->methodOne(),
> =A0 =A0$client->methodTwo()
> );
>
> ?>
>
>
>
> Andrew
>

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

Re: Execution order of PHP

am 10.03.2010 17:10:39 von Auke van Slooten

Andrew Ballard wrote:
> I'm not sure you would want to assign null to $client->system. After
> all, __set() might not be defined.
>
> I agree with Rob here. If order is really crucial, then call the
> statements in the correct order:
>
> >
> /**
> * causes $client to call __get() in order to resolve
> * 'system'
> */
> $system = $client->system;
>
>
> /**
> * You should add some handling here to make sure that
> * $system is really an object that implements your
> * multiCall() method, and not something else (like null).
> */
>
>
> $system->multiCall(
> $client->methodOne(),
> $client->methodTwo()
> );
>
> ?>

I agree with both of you. If you want it ironclad and you cannot change
the API, then this is how I would do it. The point is that I _can_
change the API, but I like how simple it looks. The backup plan is to do
something like:

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

The only problem with this is that I'm polluting the $client 'namespace'
with a __defer method. And it looks less clean... :)

Now if the consensus is that you absolutely cannot rely on the execution
order in this case (not for the order in which function parameters are
evaluated, I don't care about that) then I will just change my API and
remember with fondness what I could not have...


regards,
Auke van Slooten
Muze

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

Re: Execution order of PHP

am 10.03.2010 21:51:47 von Daniel Egeberg

On Wed, Mar 10, 2010 at 14:41, 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()
>> );
>>
>> Currently PHP always resolves $client->system (and executes the __get
> on
>> $client) before resolving the arguments to the multiCall() method
> call.
>>
>> Is this order something that is specified by PHP and so can be relied
>> upon to stay the same in the future or is it just how it currently
> works.
>>
>> If it cannot be relied upon to stay this way, I will have to rewrite
> the
>> multiCall method and API...
>
> 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.

That's not true. It's entirely possible making languages that are lazy
evaluated. Haskell is an example of that.

--=20
Daniel Egeberg

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

Re: Execution order of PHP

am 10.03.2010 22:35:28 von Jochem Maas

Op 3/10/10 1:29 PM, Auke van Slooten schreef:
> Hi,
>
> 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()
> );
>
> Currently PHP always resolves $client->system (and executes the __get on
> $client) before resolving the arguments to the multiCall() method call.
>
> Is this order something that is specified by PHP and so can be relied
> upon to stay the same in the future or is it just how it currently works.
>
> If it cannot be relied upon to stay this way, I will have to rewrite the
> multiCall method and API...

I think you can probably rely on the call order but given no formal spec
for php it's not ironclad - multiCall() will never be called before
methodOne() or methodTwo() because the return values of those are needed to
pass to multiCall() BUT you can't say for sure whether $client->system will
be evaluated before the methodOne() and methodTwo() calls ... looking at
it the code doesn't actually require it, in practice it doubt the engine
will change so dramatically that the call order would change.

but who cares. the code is full of magic, which makes it difficult to understand
and maintain ... fix it so that it's explicit about what it's doing so that
other developers who read it will grasp the concept without having to dig
into your magic methods. this solves the problem of undiscernable magic and
possible issues with resolution order in the future as well (which if they
happened would be a royal PITA to debug, given the magic methods involved)

>
> regards,
> Auke van Slooten
> Muze
>


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

Re: Execution order of PHP

am 11.03.2010 07:38:47 von Rene Veerman

You may not care about this, but from a readability perspective, i
think relying on $client->system being as special as you describe, is
not very readable.

If i'd had to read code that does what you describe, i'd be much
happier to see a datastructure be passed as was suggested elsewhere in
this thread, but even more happy to see something like this:

$client->system->specificMultiCall (
multiCallCommandCreate(array(
0 =3D> array('function1', 'f1p1', f1p2'),
1 =3D> array('function2', 'eval:f2p1', 'f2p2', 'f2p3'),
'f2p1' =3D> array('function3', 'f3p1', 'f3p2')
)
);

This structure allows for calling of any chain of methods, the array
returned by multiCallCommandCreate() can be ordered, the root of this
tree is the sequentially ordered integer keys, parameters are parsed
left-to-right as usual.

multiCallCommandCreate() can then set up an array for use by
specificMultiCall(), the one returned by the collection routine for
$client->system.
The advantages of this are possibly some extra readability, but also
some more room for expansion.


On Wed, Mar 10, 2010 at 3:13 PM, Auke van Slooten wrote:
> Bruno Fajardo wrote:
>>
>> 2010/3/10 Auke van Slooten
>>>
>>> Hi,
>>>
>>> In a hobby project I'm relying on the order in which the following piec=
e
>>> of PHP code is executed:
>>>
>>> $client->system->multiCall(
>>> =A0$client->methodOne(),
>>> =A0$client->methodTwo()
>>> );
>>
>> Can't you call the methods $client->methodOne() and
>> $client->methodTwo() before the call to $client->system->multiCall()?
>> That way, you could store they values in local variables, and then
>> pass them to the $client->system->multiCall(), assuring that those
>> methods are executed before the multiCall(). Something like:
>>
>> $methodOne =3D $client->methodOne();
>> $methodTwo =3D $client->methodTwo();
>> $client->system->multiCall($methodOne, $methodTwo);
>
> Hi,
>
> This is not what I meant. I should perhaps mention that it's an xml-rpc
> client and the method calls are remote method calls. The multiCall method
> gathers multiple method calls into a single request.
>
> The trick I'm using now is to set a private property in the $client->__ge=
t()
> method when the property you're accessing is 'system'. From then untill y=
ou
> call the method 'multiCall', instead of calling the methods (in this case
> methodOne and methodTwo) the client creates a new object with the call
> information (method name and arguments) and returns that. In multiCall al=
l
> arguments are therefor call information objects and multicall creates a
> single request based on that information.
>
> So in your example the client would simply call methodOne and methodTwo a=
nd
> return the results. Then it would try to do a multiCall with whatever the
> previous methods have returned.
>
> regards,
> Auke van Slooten
> Muze
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

Re: Execution order of PHP

am 11.03.2010 13:50:09 von Auke van Slooten

Jochem Maas wrote:
> Op 3/10/10 1:29 PM, Auke van Slooten schreef:
>> Hi,
>>
>> 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()
>> );
>>
>
> but who cares. the code is full of magic, which makes it difficult to understand
> and maintain ... fix it so that it's explicit about what it's doing so that
> other developers who read it will grasp the concept without having to dig
> into your magic methods. this solves the problem of undiscernable magic and
> possible issues with resolution order in the future as well (which if they
> happened would be a royal PITA to debug, given the magic methods involved)

I've decided to rewrite the API so it is more upfront about what it
does. Your argument about readability, when the API is unknown, is a
valid one. It now works like this:

$client->system->multiCall(
ripcord::encodeCall('methodOne'),
ripcord::encodeCall('methodTwo')
);

Thanks for all your input,
Auke van Slooten
Muze

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