Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94492 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77221 invoked from network); 12 Jul 2016 15:44:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2016 15:44:00 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.213.44 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.213.44 mail-vk0-f44.google.com Received: from [209.85.213.44] ([209.85.213.44:34476] helo=mail-vk0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/4D-17655-E3015875 for ; Tue, 12 Jul 2016 11:43:58 -0400 Received: by mail-vk0-f44.google.com with SMTP id o63so27421298vkg.1 for ; Tue, 12 Jul 2016 08:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=tH+lmB19andQi+1vBHLFPRHEGdPe97NqVYJ21rmHgoU=; b=r3sBFCji+uBX193q0Km7iJ0EmGWCWxBH/wOiaZh+Cgm18YvWYVI3y/9qf6TIkl28+v Wm36NOBXaNvCgGrrbpLCchKhgf8rTKGdc+m9hUMvCRqFwxkxq8eRYXCm/Y85z3thQ4Zi wZ2hoe4BUDh9jChUte/WCQm4pxMspJIVTksiXLnAtaw//AEe12PPFG2EjnpgiivgVY5e 3KqYo5CC33Rp0fFnbB3D5sSFJZU7BRzZ0OI11pRsPCqfOu2ofmeLUVBzJ/mhIYvTDcrR Df0Sz5VQCh5LIog76PrHoVK65dkzYJ1sJIQRQI7R6EAb+P7F8T0qtTV+qFmXCDnLqeRD paWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=tH+lmB19andQi+1vBHLFPRHEGdPe97NqVYJ21rmHgoU=; b=Vv0vWtLxRvakPtNwGngoifF8Y8rqRfuTybrRAkiLQR7t8l4HawTELqjsk5pKcqrXub TMNDRbJEb9j75uhU9e6rpooBasvbCw2KWhISoy3M8ZvYV2glSLebBZMF8heR6FJkeTKg lRmLaizjYrC8noqqgDIwqeDafpKC8ydlde05njAUFr6r6vY1DUljAMJS1mJQKi96wQi+ bJpCioL4diFKFno6TaF7dx4PrjLWY9TzG4HOmzUgiy5qhvq0rmiyJa9ODfesNp7WYjYy 4OMJiadQ/USNhN+CbwzgwQbWa/aYNQ2W0ogC6ezpvi8mcwAwFsurCy9lfwKzxw7adAxY OExg== X-Gm-Message-State: ALyK8tJejTmmaIV0tZyTNwphuRfuKsdO9Iqlzpc+MkhSCXIg+QTNmuLZK0eowwV28y6RF1O+kaPWZc62QBaADg== X-Received: by 10.31.6.18 with SMTP id 18mr1502884vkg.43.1468338235778; Tue, 12 Jul 2016 08:43:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.105.9 with HTTP; Tue, 12 Jul 2016 08:43:54 -0700 (PDT) In-Reply-To: <33e06ab7-ec7b-0cc0-d724-ede441df6c89@gmail.com> References: <86455a1e-eb57-1f30-9016-ac70c9f30bdd@gmail.com> <33e06ab7-ec7b-0cc0-d724-ede441df6c89@gmail.com> Date: Tue, 12 Jul 2016 17:43:54 +0200 Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return) From: rasmus@mindplay.dk (Rasmus Schultz) > Thinking about it, this becomes something more like a "with" keyword I was starting to think along these lines. I do like the idea of being able to specify the context for a block - though, as you say, this feature raises issues, and in e.g. Javascript, these days, it is now strongly discouraged, and prevented in strict mode. I do think it would have some potentially pretty awesome uses though - for example, in templates, assuming this statement would have a non-block counterpart (like if and while have) you could "import" a class with HTML helper methods in this way:

It also potentially lets you create highly convenient DSLs: with ($parser_helper) { $INT = seq(optional(char("-")), plus(digit())); } This would have potentially really good IDE support and offline inspections as well. I guess the biggest issue is what happens when you wrap multiple scopes? with ($a) { with ($b) { foo(); } } What happens in this case? I don't think there's any good answer to that question - if neither $b or $a implements foo(), the only thing the compiler could do, is dispatch $b->__call("foo", []) ... so you'd need some really complex logic and rules, and these constructs could have some pretty unpredictable performance implications as well. There's also the question of what happens in this case: with ($a) { bar(); } function bar() { with ($b) { fud(); } } Does it work in the local scope only, or would it be able to resolve as $a->fud() ? That's crazy, and it probably should work only in the lexical scope of the current function, but anyways - I think this feature raises a lot of ugly questions with no elegant answers... On Tue, Jul 12, 2016 at 10:36 AM, Rowan Collins wrote: > On 12/07/2016 00:14, Jesse Schalken wrote: >> >> If so, some consideration should be made as to which syntax is preferred >> to solve this problem generally for both setting properties and calling >> methods. >> >> I prefer the "obj { .. }" syntax because it mirrors object literals in >> JSON/JavaScript, object initializers in C# and C/C++ and Haskell record >> syntax, is particularly concise when nested to create large trees of >> objects, and avoids the noise of "->>" on each line. > > > All the examples you've given for that syntax are for initialisation, and > I'm not sure how readable it would be for the general "do several things in > a row" case: > > $counter { > count(), > count(), > count(), > count() > } > > Thinking about it, this becomes something more like a "with" keyword: > > with ( $counter ) { > count(); > count(); > count(); > count(); > } > > If with(){} could be used as an expression, you'd get something remarkably > close to your initialiser example: > > $this->setBlah( > with ( Blah::create(4) ) { > foo = $foo; > baz = with ( new Baz() ) { > markFixed(); > label = "Hello"; > }; > setBot(9); > } > ); > > I'm not sure if this is a good thing or not - with() statements exist in a > few languages, with varying degrees of acceptance. I don't remember seeing > one used as an expression like that before, though. > > There's a definite awkwardness of what to put on the left side of property > assignments too... > > with ( new Foo ) { var = 1 } > with ( new Foo ) { $var = 1 } > with ( new Foo ) { ->var = 1 } > > > Overall, it's an interesting idea, but the details are fiddly, and the gains > marginal, IMO. > > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >