In a new post to his site Gonzalo Ayuso has put together an example of releasing unmanaged resources similar to something C# does with its "using" functionality.
Sometimes we work with instances that needs to released even when exceptions happens. Something typical when we work with resources (Files, Database connections, …) [...] Sometimes I need collaborate with C# projects. C# is a great language. I really like it. It has a really cool feature to solve this problem: the “using” statement. Because of that we are going to build today one small library to implement something similar in PHP.
He provides a basic code example, showing how to use a "Disposable" interface with a "dispose" method that can be implemented based on the resource type you need to use. In his example, it's a "File" class that implements the interface and and global "using" function is defined to clean up the object after use. The code for the sample is also available on Github.