Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61005 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33370 invoked from network); 27 Jun 2012 17:41:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2012 17:41:04 -0000 Authentication-Results: pb1.pair.com header.from=john.lesueur@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=john.lesueur@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: john.lesueur@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:33751] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/C1-22531-FA54BEF4 for ; Wed, 27 Jun 2012 13:41:04 -0400 Received: by werm13 with SMTP id m13so1065758wer.29 for ; Wed, 27 Jun 2012 10:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=BZd3WVqZoRsXmJRMQg1jy5OQJUrNdTI2/FYVfdiK3Nk=; b=tvJyIpipWYlC/1lc410oR3lFJgBoiwlcha/AaEQcrdmbC+YwhonMCagfFMsqpDDYT5 9XM+wDJsn2RzbtWszj2SLGpkH6Scn9fjHI4LoJ4ZovAt3CSFfWAkBImTDMaKcj6VaFuZ Rnm/WcNmt7HFxv0gST81cMqV0V4+AQQm4d24QoZscyngxx2UPRkLL0Di1jfHHV7NiGHI MntqPx4WweaYyEXRkJM7O16OAenW45RJjilAxuSYyE6N9z0yvSZVYPNuEjrYi8ATpgcy 3sTapCkY57cK1ctWgJWg0QrWJfOUhcynek/u8od8EuZqNaJjHSP528dfb1VR9YOUWVPS CUvA== MIME-Version: 1.0 Received: by 10.180.86.5 with SMTP id l5mr6504779wiz.6.1340818860689; Wed, 27 Jun 2012 10:41:00 -0700 (PDT) Received: by 10.216.135.20 with HTTP; Wed, 27 Jun 2012 10:41:00 -0700 (PDT) In-Reply-To: References: Date: Wed, 27 Jun 2012 11:41:00 -0600 Message-ID: To: Michael Morris Cc: PHP Internals List Content-Type: multipart/alternative; boundary=f46d04430686e6489d04c377b7f0 Subject: Re: [PHP-DEV] Braceless Syntax extended to functions and classes (bugs #47416 and 24100) From: john.lesueur@gmail.com (John LeSueur) --f46d04430686e6489d04c377b7f0 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 27, 2012 at 11:06 AM, Michael Morris wrote: > PHP has a braceless syntax stretching back to its roots as a template > language. Frameworks which make use of php templating use these tags > quite frequently since it's harder to overlook an endif statement in a > sea of HTML tags than a brace. But what of endfunction? > > I did some look ups and found in the archive two of the most unhelpful > - bordering on rude - comments I've seen on the bug database. > > [2003-06-09 13:40 UTC] derick@php.net > The "endif;" stuff is old > legacy syntax and is definitely not the recommended way of doing > things. For my part if can be removed for PHP 5... anyway, definitely > not something we will add. > [2009-02-17 15:41 UTC] johannes@php.net > Derick'S response to #24100 > is still valid. We still prefer the {} syntax. > > > So sure "we" (whoever we is) prefer braces. I prefer them in straight > code contexts - I don't want to work with them in HTML templates. > This said, the need to do a function or class closure inside a > template is rare, bordering on non-existent. > > But for functions there is one case - anonymous functions - > specifically for recursion. Here's a live example that renders a > nested list. > > $render = function( $categories ) use (&$render) { > ob_start() ?> >
    > >
  • > 0): > echo $render( $category['children'] > ); > endif ?> > >
  • >
> } > ?> > > This would be ever so slightly easier to read with endfunction. > > $render = function( $categories ) use (&$render): > ob_start() ?> >
    > >
  • > 0): > echo $render( $category['children'] > ); > endif ?> > >
  • >
> endfunction > ?> > > I'm not going to raise too much of a fuss over it. At the end of the > day, it's a small change. But the elitist, dismissive comments to the > idea from the team at the time were unwarranted. > > Also, I have to wonder if the position on this has changed any at all? > Particularly since > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > If those are the most unhelpful comments you've seen in the bug database, you haven't been looking hard enough :) This does seem like an improvement to readability, but in an edge case that I would try to avoid. Defining functions in templates just seems wrong. I know your example isn't meant to be taken as the only archtype, but an example of how I would deal with recursion:
  • 0): $tmp = $categories; $categories = $category['children']; include "renderCategories.php" $categories = $tmp; endif ?>
Not sure how great an idea doing a recursive include on a template would be, but I also prefer using a templating engine, so I may be biased to work in a different way. Thanks, John --f46d04430686e6489d04c377b7f0--