Re: [PHP] Execution order of PHP

[email protected] (Auke van Slooten)
Newsgroups php.general
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.