Re: speaking of control structures...
| From: | Robert Cummings | Date: | Wed, 06 May 2009 12:49:37 +0000 |
| Subject: | Re: speaking of control structures... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292341@lists.php.net to get a copy of this message | ||
On Wed, 2009-05-06 at 08:43 -0400, Tom Worster wrote:
> On 5/6/09 6:56 AM, "Marcus Gnaß" <gonatan@gmx.de> wrote:
>
> > Tom Worster wrote:
> >> there's a control structure i wish php had: a simple block that you can
> >> break out of, e.g.
> >
> > As Maarten pointed out you could use a function. Another alternative is
> > to use Exceptions which might be the most proper way to do it.
>
> in a thread off-list i commented on the use of a function. here's what i
> said:
>
> yes, it's just like that. i could wrap a function around the logic. and
> sometimes i use that trick.
>
> the downside to that is access to globals. for many of my scripts there's a
> common pattern:
>
> 1 get set up.
> 2 process inputs, checking and preparing data for use 3 and 4 or aborting to
> an error handler at the end of this section (which is what the breaks all
> jump to) if there's a problem with the input.
> 3 do some work
> 4 prepare an output page
>
> in this scheme, it's convenient if 2, 3 and 4 all have access to the same
> namespace, so i don't usually use the function approach.
Then create a shared namespace...
$GLOBALS['myWhateverWorksNamespace']['varName'] = 'varValue';
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP