Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5006 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65497 invoked by uid 1010); 26 Oct 2003 11:50:39 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 65473 invoked by uid 1007); 26 Oct 2003 11:50:39 -0000 Message-ID: <20031026115039.65472.qmail@pb1.pair.com> To: internals@lists.php.net References: <20031024200902.90818.qmail@pb1.pair.com> Date: Sun, 26 Oct 2003 09:50:38 -0200 Lines: 152 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Posted-By: 200.196.104.198 Subject: Re: finally again From: cunha17@uol.com.br ("Cristiano Duarte") > 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