Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83678 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15745 invoked from network); 24 Feb 2015 16:53:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 16:53:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thomasbley.de from 85.13.137.24 cause and error) X-PHP-List-Original-Sender: mails@thomasbley.de X-Host-Fingerprint: 85.13.137.24 dd15934.kasserver.com Received: from [85.13.137.24] ([85.13.137.24:33664] helo=dd15934.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/D1-05669-D8CACE45 for ; Tue, 24 Feb 2015 11:53:34 -0500 Received: from dd15934.kasserver.com (dd0800.kasserver.com [85.13.143.204]) by dd15934.kasserver.com (Postfix) with ESMTPSA id 406D526196F; Tue, 24 Feb 2015 17:53:31 +0100 (CET) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 210.213.49.51 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: References: To: internals@lists.php.net, pjsturgeon@gmail.com Message-ID: <20150224165331.406D526196F@dd15934.kasserver.com> Date: Tue, 24 Feb 2015 17:53:31 +0100 (CET) Subject: Re: [PHP-DEV] [RFC] Anonymous Classes From: mails@thomasbley.de ("Thomas Bley") here is an example for opening a mysqli connection only when the first query is executed: $c = new class extends mysqli { public function query($query, $resultmode = MYSQLI_STORE_RESULT) { if (empty($this->host_info)) parent::real_connect('127.0.0.1', 'user', 'pwd', 'db'); return parent::query($query, $resultmode); } } // do sth for some time $->query('...'); // triggers real_connect $->query('...'); // connection is already established I haven't tested this, so I'm only intending to present the idea. Regards Thomas Philip Sturgeon wrote on 24.02.2015 14:52: > Good day! > > https://wiki.php.net/rfc/anonymous_classes > > There's a little RFC + patch that Joe Watkins put together, and as > before with the ArrayOf RFC, I'll be helping out. > > So, lets get this discussion rolling. > > It was declined for PHP 5 some time ago, and has returned now to try for PHP 7. > > The usage of anonymous classes to some will be instantly offensive, > but really it comes down to the use case. The usage of anonymous > functions compared to declared functions is pretty much the exact same > thing as anonymous classes. > > Other than examples on the RFC, Fractal would certainly be happy to > have them: http://fractal.thephpleague.com/transformers/ > > Defining a class properly is certainly still going to be the majority > of uses of classes in PHP. That helps with the Optimizer, and helps > code reuse. > > Sadly due to the way in which people have had ONE CLASS ONE FILE > drilled into their head since PEAR and continuing through Zend and > PSR-0, it can become a PITA to add some simple functionality if a > small class is needed for one tiny thing. > > Anonymous functions alleviate that annoyance with a simple and > consistent feature that just give people a nice simple option to get > their jobs done, without hitting autoloaders and file systems to do > it. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >