Re: [PHP] Execution order of PHP
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
Re: [PHP] Execution order of PHP
2010/3/10 Auke van Slooten a...@muze.nl 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. 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 = $client-methodOne(); $methodTwo = $client-methodTwo(); $client-system-multiCall($methodOne, $methodTwo); Cheers, Bruno. 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Execution order of PHP
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. 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: [PHP] Execution order of PHP
Bruno Fajardo wrote: 2010/3/10 Auke van Slooten a...@muze.nl 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: [PHP] Execution order of PHP
2010.03.10. 14:41 keltezéssel, Bob McConnell írta: 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. 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 I think it cannot be that the evaluation order of the parameters is 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 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 smime.p7s Description: S/MIME Cryptographic Signature
Re: [PHP] Execution order of PHP
On Wed, 2010-03-10 at 15:20 +0100, Sándor Tamás wrote: 2010.03.10. 14:41 keltezéssel, Bob McConnell írta: 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. 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 I think it cannot be that the evaluation order of the parameters is 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 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 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
Re: [PHP] Execution order of PHP
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: [PHP] Execution order of PHP
From: Sándor Tamás 2010.03.10. 14:41 keltezéssel, Bob McConnell írta: 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. 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 think it cannot be that the evaluation order of the parameters is 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 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: [PHP] Execution order of PHP
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: [PHP] Execution order of PHP
2010/3/10 Auke van Slooten a...@muze.nl: Bruno Fajardo wrote: 2010/3/10 Auke van Slooten a...@muze.nl 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. 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 = 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. 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: [PHP] Execution order of PHP
On Wed, Mar 10, 2010 at 9:54 AM, Bruno Fajardo bsfaja...@gmail.com wrote: [snip] 2010/3/10 Auke van Slooten a...@muze.nl: 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. 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 = 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: ?php /** * 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() ); ? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
2010/3/10 Andrew Ballard aball...@gmail.com: On Wed, Mar 10, 2010 at 9:54 AM, Bruno Fajardo bsfaja...@gmail.com wrote: [snip] 2010/3/10 Auke van Slooten a...@muze.nl: 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. 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 = 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. 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: ?php /** * causes $client to call __get() in order to resolve * 'system' */ $system = $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. /** * 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: [PHP] Execution order of PHP
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: ?php /** * 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: [PHP] Execution order of PHP
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: [PHP] Execution order of PHP
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 = array('function1', 'f1p1', f1p2'), 1 = array('function2', 'eval:f2p1', 'f2p2', 'f2p3'), 'f2p1' = 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 a...@muze.nl wrote: Bruno Fajardo wrote: 2010/3/10 Auke van Slooten a...@muze.nl 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php