Ferenc Kovacs wrote (on 13/08/2014):
I think you misunderstood that part, I was thinking about a state machine like this:

 1. function doStuff(){
 2. switch($state){
 3. case OPENDOOR:
 4. if(!opendoor()){
 5. break;
 6.       }
 7.     $state = SITDOWN;
 8. case SITDOWN:
 9. if(!sitdown()){
10. break;
11.       }
12.     $state = SIPWHISKEY;
13. case SIPWHISKEY:
14.       sipwhiskey();
15.   }
16. }


where you modify the switch variable in one case and fall through into another. as I mentioned I don't have a reasonable use-case for multiple defaults, but I can see some for multiple case labels in general, and I don't think that it is better to have different behavior for case and default in this regard.


The assignments to $state in that code do not make any difference to execution, control simply flows forwards whenever there is no "break".

$state is only tested once, to select the initial label to jump to, so no amount of reassigning it, or adding duplicate labels, can ever cause a second jump.

I'm tempted to write a PHP script that emulates the switch execution by building a set of if and goto statements, which might make some of this behaviour clearer (not just for this discussion, but for other confusion I've seen elsewhere), but I don't have time right now.

Reply via email to