> Hi internals ! > > I came into a problem when writing an IDL to PHP5 language mapping > specification and an IDL to PHP5 language compiler. I'm using the community > OpenORB IDL-to-Java compiler as a base for writing the IDL-to-PHP5 compiler, > in fact, it is a translation from Java to PHP5. Everything is ok except the > "finally" clause wich doesn't exists in Zend Engine 2. I know that many of > you think that "finally" is useless but consider this case, and if anyone > have a simple and elegant solution without implementing "finally" I'll be > glad to listen. > The code would be like this if we had finally: > <? > ... > $_input = null; > try { > $_output = $this->_request('bind',true); > org__omg__CosNaming__NameHelper::write($_output,$n); > $_output->write_Object($obj); > $_input = $this->_invoke($_output); > return; > } catch(org__omg__CORBA__portable__RemarshalException $_exception) { > continue; > } catch(org__omg__CORBA__portable__ApplicationException $_exception) { > $_exception_id = $_exception->getId(); > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__NotFoundHelper::id()) { > throw > org__omg__CosNaming__NamingContextPackage__NotFoundHelper::read($_exception- > >getInputStream()); > } > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__CannotProceedHelper::id()) { > throw > org__omg__CosNaming__NamingContextPackage__CannotProceedHelper::read($_excep > tion->getInputStream()); > } > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__InvalidNameHelper::id()) { > throw > org__omg__CosNaming__NamingContextPackage__InvalidNameHelper::read($_excepti > on->getInputStream()); > } > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__AlreadyBoundHelper::id()) { > throw > org__omg__CosNaming__NamingContextPackage__AlreadyBoundHelper::read($_except > ion->getInputStream()); > } > throw new org__omg__CORBA__UNKNOWN("Unexpected User Exception: > $_exception_id"); > } catch(Exception $_exception) { > throw $_exception; > } finally { > $this->_releaseReply($_input); > } > ... > ?> > > Since we don't have finally, the current code is: > > <? > ... > $_input = null; > try { > $_output = $this->_request('bind',true); > org__omg__CosNaming__NameHelper::write($_output,$n); > $_output->write_Object($obj); > $_input = $this->_invoke($_output); > $this->_releaseReply($_input); //PHP still does not have FINALLY !!! > return; > } catch(org__omg__CORBA__portable__RemarshalException $_exception) { > $this->_releaseReply($_input); //PHP still does not have FINALLY !!! > continue; > } catch(org__omg__CORBA__portable__ApplicationException $_exception) { > $_exception_id = $_exception->getId(); > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__NotFoundHelper::id()) { > $this->_releaseReply($_input); //PHP still does not have FINALLY > !!! > throw > org__omg__CosNaming__NamingContextPackage__NotFoundHelper::read($_exception- > >getInputStream()); > } > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__CannotProceedHelper::id()) { > $this->_releaseReply($_input); //PHP still does not have FINALLY > !!! > throw > org__omg__CosNaming__NamingContextPackage__CannotProceedHelper::read($_excep > tion->getInputStream()); > } > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__InvalidNameHelper::id()) { > $this->_releaseReply($_input); //PHP still does not have FINALLY > !!! > throw > org__omg__CosNaming__NamingContextPackage__InvalidNameHelper::read($_excepti > on->getInputStream()); > } > if ($_exception_id == > org__omg__CosNaming__NamingContextPackage__AlreadyBoundHelper::id()) { > $this->_releaseReply($_input); //PHP still does not have FINALLY > !!! > throw > org__omg__CosNaming__NamingContextPackage__AlreadyBoundHelper::read($_except > ion->getInputStream()); > } > $this->_releaseReply($_input); //PHP still does not have FINALLY !!! > throw new org__omg__CORBA__UNKNOWN("Unexpected User Exception: > $_exception_id"); > } catch(Exception $_exception) { > $this->_releaseReply($_input); //PHP still does not have FINALLY !!! > throw $_exception; > } > $this->_releaseReply($_input); //PHP still does not have FINALLY !!! > ... > ?> > > IMHO, I think that replicating the finally code at the end of every catch > block, before every throw/return statement and at the end of the try/catch > statement justify the need of "finally". > If there is another aproach without "finally" and without code redundancy, I > really need it. >
Any ideas ? Best Regards, Cristiano Duarte -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php