Improved retry function for igorw/retry, as proposed by @acleon.
Benefits:
- Appears to use fewer opcodes (This is the 1st time I've used VLD, I could be wrong)
- Doesn't use goto
<?php | |
$handler = new RotatingFileHandler(ABSPATH . '../logs/log.log', 0, Logger::DEBUG, true, 0777); | |
try { | |
$record = array( | |
'message' => (string) "Write test", | |
'context' => null, | |
'level' => Logger::DEBUG, | |
'level_name' => 'DEBUG', |
<?php | |
$logger = new Logger('my logger'); | |
// log DEBUG messages to file when there's at least a NOTICE | |
$fileHandler = new RotatingFileHandler(ABSPATH . '../logs/log.log', 0, Logger::DEBUG, true, 0777); | |
$fingersCrossedHandler = new FingersCrossedHandler($fileHandler, Logger::NOTICE, 1000); | |
$logger->pushHandler($fingersCrossedHandler); |
<?php | |
class Bar{} | |
$bars = [new Bar, new Bar, new Bar]; | |
$ints = [1, 2, 3]; | |
// without variadics | |
// lots of manual type checking | |
function oldFoo($bars) | |
{ |
<?php | |
class BreakOut extends Exception {} | |
function mapGenerator(array $arr, $callback) | |
{ | |
$ret = []; | |
foreach ($arr as $val) { | |
try { | |
yield $callback($val); |
Improved retry function for igorw/retry, as proposed by @acleon.
Benefits:
<?php | |
$stack = []; | |
$labels = []; | |
$pointer = 0; | |
$instructions = []; | |
/** | |
* @param $stack | |
* @param $instructions |
class Repo | |
{ | |
public function fetchByName($name) | |
{ | |
$entity = $this->em->fetch(['name' => $name]); | |
if (!$entity) { | |
$entity = new NullEntity($name); | |
} | |
$this->dispatcher->dispatch(new EntityRetrievedEvent($entity)); | |
return $entity; |
<?php | |
class Foo { | |
public function __construct($i) | |
{ | |
$this->bar = $i; | |
} | |
} | |
$start = microtime(true); | |
$count = 1000000; |
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |