note 123914 added to control-structures.switch
| From: | Manucyan@php.net | Date: | Fri, 07 Jun 2019 14:24:39 +0000 |
| Subject: | note 123914 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211194@lists.php.net to get a copy of this message | ||
Some tests:
switch ('aaaaa') {
default : echo "DEFAULT TOP 1"; break;
default : echo "DEFAULT TOP 2"; break;
case 'aaaaa': echo "CASE TOP 1"; break;
case 'aaaaa': echo "CASE TOP 2"; break;
default : echo "DEFAULT BOTTOM 1"; break;
default : echo "DEFAULT BOTTOM 2"; break;
case 'aaaaa': echo "CASE BOTTOM 1"; break;
case 'aaaaa': echo "CASE BOTTOM 2"; break;
}
//return ------> CASE TOP 1
switch ('SOMETHING_THAT_DOESN_T_EXIST') {
default : echo "DEFAULT TOP 1"; break;
default : echo "DEFAULT TOP 2"; break;
case 'aaaaa': echo "CASE TOP 1"; break;
case 'aaaaa': echo "CASE TOP 2"; break;
default : echo "DEFAULT BOTTOM 1"; break;
default : echo "DEFAULT BOTTOM 2"; break;
case 'aaaaa': echo "CASE BOTTOM 1"; break;
case 'aaaaa': echo "CASE BOTTOM 2"; break;
}
//return ------> DEFAULT BOTTOM 2
Some observations:
- no errors if several identical boxes or defaultes
- the last defect takes over
- the first of the boxes takes the hand
- we can put the default at the top (indeed sometimes it's more intuitive)
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.130.26 (proxied: 80.15.41.4)
----
Manual Page -- http://php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/123914
Del: integrated -- https://master.php.net/note/delete/123914/integrated
Del: useless -- https://master.php.net/note/delete/123914/useless
Del: bad code -- https://master.php.net/note/delete/123914/bad+code
Del: spam -- https://master.php.net/note/delete/123914/spam
Del: non-english -- https://master.php.net/note/delete/123914/non-english
Del: in docs -- https://master.php.net/note/delete/123914/in+docs
Del: other reasons-- https://master.php.net/note/delete/123914
Reject -- https://master.php.net/note/reject/123914
Search -- https://master.php.net/manage/user-notes.php