Re: finally again
| From: | Andrew Smith | Date: | Sun, 26 Oct 2003 14:01:14 +0000 |
| Subject: | Re: finally again | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-5011@lists.php.net to get a copy of this message | ||
Cristiano Duarte wrote:
What's the status of your project anyway ? I'm not shure, but I guess Marcus said that finally is useless in PHP...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 !
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.
Best Regards, Andrew Smith, Dr.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.