Re: Continued try blocks

From: Date: Mon, 29 Apr 2013 15:12:27 +0000
Subject: Re: Continued try blocks
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-67191@lists.php.net to get a copy of this message
On Mon, 2013-04-29 at 08:25 +0200, Lars Strojny wrote: > Hi Julien, > > I'm still on the fence, not sure if it isn’t too opaque. > > Am 26.04.2013 um 16:41 schrieb Julien Pauli <jpauli@php.net>: > [...] > > One question regarding scoping: does the next statement inherit the scope of the catch block > like this? > > try { > $user = $repository->findById(123); > $user->setName($name); > $em->save($user); > return true; > } catch (NotFoundException $e) { > $user = new User(); > continue; > } catch (ValidationException $e) { > $user->setName($this->stripInvalidChars($name)); > continue; > } catch (PersistenceException $e) { > return false; > } In this specific case it would have to, as PHP has function-level scoping, no block scoping. But this really like abusing exceptions ... johannes

« previous php.internals (#67191) next »