Skip to content

Instantly share code, notes, and snippets.

@ieatkillerbees
Last active June 3, 2019 18:55
Show Gist options
  • Save ieatkillerbees/60c83c7dc0885a86497a to your computer and use it in GitHub Desktop.
Save ieatkillerbees/60c83c7dc0885a86497a to your computer and use it in GitHub Desktop.
Important Multi-Default Use Case
<?php
// Apparently I need to point out that this is a joke?
$foo = 101;
switch (true)
{
default:
less:
echo "$foo < 100!";
break;
default:
more:
echo "$foo > 100!";
break;
default:
same:
echo "$foo == 100!";
break;
default:
if ($foo < 100) {
goto less;
} elseif ($foo > 100) {
goto more;
} elseif ($foo == 100) {
goto same;
}
break;
}
@cryptiklemur
Copy link

or,

<?php
$foo = 101;

switch (true)
{
    case $foo < 100:
        echo "$foo < 100!";
        break;
    case $foo > 100:
        echo "$foo > 100!";
        break;
    case $foo == 100:
        echo "$foo == 100!";
        break;
}

OR.

<?php
$foo = 101;

if ($foo < 100) {
    echo "Less";
} elseif ($foo > 100) {
    echo "More";
} else {
   echo "Same";
}

// OR!!!!

echo $foo == 100 ? 'Same' : ($foo < 100 ? 'Less' : 'More');

@kbanman
Copy link

kbanman commented Aug 13, 2014

If you need to use goto to demonstrate a use case, I would hardly consider it an important case. As @aequasi points out, there are sensible alternatives.

Copy link

ghost commented Aug 14, 2014

"Important"

@arosemena
Copy link

if you want to ever be taken seriously by an employer either delete this gist or never send them your github account

@jakeasmith
Copy link

Hahahaha... This is fantastic 👍

@collegeman
Copy link

Hey @SQuinones, we met at the DC PHP meetup the other night. I'd love to chat with you sometime about some of the tech we were discussing. Of particular interest to me is the way you've integrated Composer into your workflow—I'm accustomed to building my own libraries in context, i.e., integrated into the project(s) they were born for, and my traditional approach to this (Git submodules) doesn't work with Composer. This immediately takes me back to my Java days where I had the exact same problem using Maven. I'd love to chat with you about this—either I'm doing it wrong, or someone needs to patch up Composer to support my workflow! :) Please hit me up on Skype (acollegeman) or just e-mail aaroncollegeman@gmail.com. Cheers!

@jcarouth
Copy link

A+ use case. Will adopt in all my legacy projects and projects I intend to bequeath to those I disdain.

@stoph
Copy link

stoph commented Jun 3, 2015

@arosemena, as her employer, I love it! Being able to come up with this is why Samantha is awesome.

@aeaia
Copy link

aeaia commented Jun 3, 2019

LGTM

@jrode
Copy link

jrode commented Jun 3, 2019

👍 can you merge this soon, i am blocked because i need this for my branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment