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
> 


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to