Skip to content

Instantly share code, notes, and snippets.

@fzaninotto
Created December 20, 2011 19:31
Show Gist options
  • Select an option

  • Save fzaninotto/1502867 to your computer and use it in GitHub Desktop.

Select an option

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";
}
@fzaninotto

Copy link
Copy Markdown
Author

Oh yes it works ;)

@fzaninotto

Copy link
Copy Markdown
Author

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

@willdurand

Copy link
Copy Markdown

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
Copy Markdown
Author

Then it's not a new idea :(

@katanacrimson

Copy link
Copy Markdown

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