Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69383 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32054 invoked from network); 27 Sep 2013 09:42:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Sep 2013 09:42:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=terence.copestake@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=terence.copestake@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.54 as permitted sender) X-PHP-List-Original-Sender: terence.copestake@gmail.com X-Host-Fingerprint: 209.85.216.54 mail-qa0-f54.google.com Received: from [209.85.216.54] ([209.85.216.54:35768] helo=mail-qa0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/A6-28456-30355425 for ; Fri, 27 Sep 2013 05:42:28 -0400 Received: by mail-qa0-f54.google.com with SMTP id bv4so318245qab.20 for ; Fri, 27 Sep 2013 02:42:25 -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=SunMoWR47LhYSrwokLQYvWztKdIMVIBj1u5lg5HLrdY=; b=j0lGs3/wSbZgSHuJ/joGvRmvXe6PvzOdgwceMfCFkufD6x8SLcICrhwdtwcZ/sHEkg enMJ+qB2EyV1suw1UjSctFmRTUY/XCs8XGYwsxiciiPkeshdL7/rAfxdEMtMyGfcs7f7 QgujN1X+DMqHUBgadYH1ZQXdT1gcd/zVm6OSuISl0va1yy3ycXNopNztkJQlLIyduxed F1xvpO8DwCoe1mCoEvLw+GddHd/Ni6AwkunygZNhLEbpirN/8504fBNK5X9W0IgVJfWB qNhsN50LucVUf45MWMtclq0f2VNDYCdKQV+OZFeM0AHIU6ORkcaMCkcpkgahIyorA2gy Eoxw== MIME-Version: 1.0 X-Received: by 10.49.50.232 with SMTP id f8mr7483246qeo.63.1380274945712; Fri, 27 Sep 2013 02:42:25 -0700 (PDT) Received: by 10.140.90.69 with HTTP; Fri, 27 Sep 2013 02:42:25 -0700 (PDT) In-Reply-To: References: <5241F11C.5080707@php.net> <008301ceb967$b49ab190$1dd014b0$@tutteli.ch> <524205D8.8000608@php.net> <5242ADAE.2080007@php.net> <5242E88D.90407@php.net> <5244095F.3090005@php.net> Date: Fri, 27 Sep 2013 10:42:25 +0100 Message-ID: To: Sebastian Krebs Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7bdc0d20d4e9b004e75a4de4 Subject: Re: [PHP-DEV] RFC: Anonymous Classes From: terence.copestake@gmail.com (Terence Copestake) --047d7bdc0d20d4e9b004e75a4de4 Content-Type: text/plain; charset=ISO-8859-1 > Just ... Isn't that something, we can simply keep out of _this_ RFC and > create separate RFC(s) for it later? Like it was done with "$this in > Closures"? Do we want another 5.3/5.4 closures situation? Why not iron it all out to begin with? If there's a sound, logical reason not to implement the functionality in question, that's fine. I don't understand why we keep reiterating "keeping it simple" as if that is in itself an excuse to, in effect, rush it through half-baked. In the RFC, there are use cases citing languages like Java to support this - a language in which anonymous classes and the methods in which they're defined, share scope. Can we then say, let's do it because it's useful in other languages, but let's not offer the functionality that those languages do? Also, my proposed use case being practical in the real world hangs on resolving the scope issue, as I struggle to look past the difficulties I'd have trying to use this in my code when it's unable to interact with the object instance in which it is being used. That's all I'll say on that now; it's becoming circular. If you want to update my use case in the RFC, here's an expanded example of what I imagine. I've lifted code from the documentation for Sentry* and below it, written an alternative anonymous class API example. * I have no affiliation with Sentry / other membership packages are available. try { // Find the user using the user id $user = Sentry::findUserById(1); // Log the user in Sentry::login($user, false); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { echo 'User not activated.'; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { echo 'User not found.'; } // Following is only needed if throttle is enabled catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $time = $throttle->getSuspensionTime(); echo "User is suspended for [$time] minutes."; } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { echo 'User is banned.'; } becomes: $user = Sentry::findUserById( 1, (new class implements Cartalyst\Sentry\LoginHandlerInterface { public function onLoginRequired() { echo 'Login field is required.'; } public function onUserNotActivated() { echo 'User not activated.'; } public function onUserNotFound() { echo 'User not found.'; } // Following is only needed if throttle is enabled public function onUserSuspended() { $time = $throttle->getSuspensionTime(); echo "User is suspended for [$time] minutes."; } public function onUserBanned() { echo 'User is banned.'; } public function onSuccess() { // Log the user in Sentry::login($user, false); } }) ); --047d7bdc0d20d4e9b004e75a4de4--