Skip to content

Fluent interface compact syntax #252

@thekid

Description

@thekid

Scope of Change

A shortened syntax for fluent interfaces will be allowed.

Rationale

Omit typing return $this;.

Functionality

The this keyword will be reused as the method's return type. The following two are equivalent:

// Current definition
public class URL {
  protected string $host;

  public self setHost(string $host) {
    $this.host= $host;
    return $this;
  }
}

// New and shortened version
public class URL {
  protected string $host;

  public this setHost(string $host) {
    $this.host= $host;
  }
}

If we combine this with the compact member assignment syntax from RFC #240, we can even write:

public class URL {
  protected string $host;

  public this setHost($this.host) { }
}

Security considerations

n/a

Speed impact

None, resolved during compile time.

Dependencies

n/a

Related documents

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions