Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5011 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16494 invoked by uid 1010); 26 Oct 2003 14:01:14 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 16470 invoked by uid 1007); 26 Oct 2003 14:01:14 -0000 Message-ID: <20031026140114.16469.qmail@pb1.pair.com> To: internals@lists.php.net Date: Sun, 26 Oct 2003 12:01:14 -0200 User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 References: <20031024200902.90818.qmail@pb1.pair.com> <20031026115039.65472.qmail@pb1.pair.com> In-Reply-To: <20031026115039.65472.qmail@pb1.pair.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 200.196.104.198 Subject: Re: finally again From: ccd73@uol.com.br (Andrew Smith) Cristiano Duarte wrote: >>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. That's great! An IDL to PHP compiler is really needed ! What's the status of your project anyway ? I'm not shure, but I guess Marcus said that finally is useless in PHP... >>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($_exception->getInputStream()); >> } >> if ($_exception_id == org__omg__CosNaming__NamingContextPackage__InvalidNameHelper::id()) { >> throw org__omg__CosNaming__NamingContextPackage__InvalidNameHelper::read($_exception->getInputStream()); >> } >> if ($_exception_id == org__omg__CosNaming__NamingContextPackage__AlreadyBoundHelper::id()) { >> throw org__omg__CosNaming__NamingContextPackage__AlreadyBoundHelper::read($_exception->getInputStream()); >> } >> throw new org__omg__CORBA__UNKNOWN("Unexpected User Exception:$_exception_id"); >> } catch(Exception $_exception) { >> throw $_exception; >> } finally { >> $this->_releaseReply($_input); >> } >> ... >>?> Humm... >> >>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($_exception->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($_exception->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($_exception->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". Agreed. You pointed out an example that really needs finally. >>If there is another aproach without "finally" and without code redundancy, I really need it. I can't think of another solution right now. But if I figure out something I'll let you know. Best Regards, Andrew Smith, Dr.