Skip to content

Instantly share code, notes, and snippets.

@fzaninotto
Created December 20, 2011 19:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzaninotto/1502867 to your computer and use it in GitHub Desktop.
Save fzaninotto/1502867 to your computer and use it in GitHub Desktop.
Catch Interface
<?php
interface Bar {}
class Foo extends Exception implements Bar {}
try
{
throw new Foo();
} catch (Bar $e) {
echo "good!\n";
}
@willdurand
Copy link

Does it work ?

@fzaninotto
Copy link
Author

Oh yes it works ;)

@fzaninotto
Copy link
Author

I'm so happy I think I'll blog about it. Does any other library use this?

@willdurand
Copy link

Symfony2 components are using this way, at least the Serializer: https://github.com/symfony/symfony/tree/master/src/Symfony/Component/Serializer/Exception

@fzaninotto
Copy link
Author

Then it's not a new idea :(

@katanacrimson
Copy link

Wonder if you can do this with Traits in PHP 5.4.

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