codeguy/Slim — pull request #706 by marcioAlmada (2013-12-23 07:43:41+00:00)
Title: Detect circular middleware stacks and fix opaque fatal error

This pull request aims to enhance Slim\App behavior when encountering circular middleware stacks. Instead of a PHP Fatal error, now an exception is thrown:

```php
add($middleware);
$app->add($middleware);
$app->run(); // fatal error
```

Before:
> Fatal error: Maximum function nesting level of '100' reached. aborting! [...]

After:
> RuntimeException: Circular Middleware setup detected. Tried to queue the same Middleware instance (CustomMiddleware) twice.

The fatal error can be hard to debug mostly because of it's opaque error message. This usually happens by some accident in userland code and deserves a more comprehensible message IMMO.

Cheers!