wushu06
2/18/2020 - 9:50 AM

Tips

$discountAmount = abs($order->getDiscountAmount());

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

yield

This function is using yield:

function a($items) {
    foreach ($items as $item) {
        yield $item + 1;
    }
}

It is almost the same as this one without:

function b($items) {
    $result = [];
    foreach ($items as $item) {
        $result[] = $item + 1;
    }
    return $result;
}

value use php7.1

brew untap exolnet/deprecated

callback / callable

function callFunc($name, $arg, $secondArg)
{
    $name(...$arg);
    echo $secondArg;
    
}

callFunc(function(...$a){
    print_r($a);
}, ['fpp', 'bar'], 'extra param');

tap

public function generateUseAndReturnThing($input)
{
    $thing = $this->thingFromInput($input);

    $this->doActionToThing($thing);

    return $thing;
}
// refactor to:
public function generateUseAndReturnThing($input)
{
    return tap($this->thingFromInput($input), function ($thing) {
        $this->doActionToThing($thing);
    });
}