This is Doctrine common's proxy generator stuff:

https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Proxy/ProxyGenerator.php#L203-L209