* @return string
*/
function __toString() {
- return (string) $this->expression . $this->next;
+ $string = $this->expression;
+ if ($this->next) {
+ $string .= " " . $this->next;
+ }
+ return (string) $string;
}
/**
* @throws \UnexpectedValueException if any expr is NULL
*/
function add(Expr $next) {
- if ($this->isNull() || $next->isNull()) {
+ if ($this->isNull()) {
throw new \UnexpectedValueException("Cannot add anything to NULL");
}
- for ($that = $this; $that->next; $that = $that->next);
- $that->next = $next;
+ if ($this->next) {
+ $this->next->add($next);
+ } else {
+ $this->next = $next;
+ }
return $this;
}
}