public function __set($property, $value) { $this->value->{$property} = $value; return new static($value); } public function __call($name, $arguments) { $method = null; if (is_object($this->value) && is_callable(array($this->value, $name))) { $method = array($this->value, $name); } elseif (isset(static::$methods[$name])) { $method = array(static::$methods[$name], $name); array_unshift($arguments, $this->value); } else { throw new \BadMethodCallException('Unknown method "' . $name . '".'); } $result = call_user_func_array($method, $arguments); return new static($result); } public function __toString() { return (string) $this->value; } } // Register default helpers... Some better place for that? Value::registerHelper(new \Colada\Helpers\TypeHelper()); Value::registerHelper(new \Colada\Helpers\NumericHelper()); Value::registerHelper(new \Colada\Helpers\StringHelper()); Value::registerHelper(new \Colada\Helpers\CollectionHelper()); Value::registerHelper(new \Colada\Helpers\ComparisonHelper());