PHP: Executing a method conditionally

We’re going back to using when and unless

if ($package->isBig()) {
$transport->useVan();
}
if ($package->isFragile()) {
$transport->handleWithCaution();
}
if ($weather->isDangerous()) {
$transport->notifyPossibleDelay();
}
return $transport->deliver();
$transport->when($package->isBig())->useVan()->deliver();

Catching the next method, programatically

public function when($value)
{
return new Container($this, $value);
}

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store