Edd Mann demonstrates a nice trait to add OrElse functionality to a class via a trait. With it you can do things like:

[code]

$cart = $repository->findByIdOrElse(1, new ShoppingCart); $cart = $repository->findByIdOrElse(1, function () { return new ShoppingCart; });

[/code]

http://tech.mybuilder.com/optional-value-control-flows-in-php-using-traits-and-magic-methods/