Re: Re: Are exceptions allowed in php core?

From: Date: Sun, 02 Sep 2012 00:27:02 +0000
Subject: Re: Re: Are exceptions allowed in php core?
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-62640@lists.php.net to get a copy of this message
On 09/01/2012 04:51 PM, Gustavo Lopes wrote > * In fact, if there is a unifying theme in the usage of exceptions in > PHP, is that exceptions are used when OOP interfaces are involved (see > Zend interfaces, SPL, DateTime and PDO -- though optional there). The > core vs. non-core argument only looks attractive because there are few > built-in classes in the core. I think this is drifting off-topic. Whether or not a generator is an object is an implementation detail. If I write: $things = getStuff(); foreach($things as $thing) { do_some($thing); } which is very normal PHP that you see in millions of lines of code, I would not expect to have to wrap my foreach in a try/catch here. Even if I am used to exceptions and might have: $things = getStuff(); foreach($things as $thing) { try { do_some($thing); } catch (Exception $e) { echo $e->getMessage(); } } this is still going to fatal on me eventually with an uncaught exception on the foreach if, for example, I pass the generator a second time to something and it has run off the end. This is something you don't have to worry about currently and I think it will cause headaches for people when they start passing generators around. In theory I should be able to pass a generator to any existing code that takes an array without having to worry about modifying that code to catch foreach exceptions. And yes, I know it is actually a generator exception, but to the average user it will look like it is foreach throwing. -Rasmus

« previous php.internals (#62640) next »