Send With Confidence
Partner with the email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.
Time to read: 2 minutes
Partner with the email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.
<?php | |
class Fluent { | |
function __construct($cache) { | |
$this->cache = ($cache ? $cache : []); | |
} | |
// Build the cache, and handle special cases | |
public function _($name) { | |
array_push($this->cache, $name); | |
return new Fluent($this->cache); | |
} | |
// Final method call | |
public function method() { | |
return $this->cache; | |
} | |
// Reflection | |
public function __call($name, $args) { | |
return $this->_($name); | |
} | |
} | |
$fluent = new Fluent; | |
$chain = $fluent->hello()->world(); | |
print_r($chain->method()); | |
// 'for' demonstrates handling special cases | |
$new_chain = $chain->thanks()->_("for")->all()->the()->fish(); | |
print_r($new_chain->method()); |