xp-forge / partial

Partials: Compile-time metaprogramming
0 stars 0 forks source link

Constructor transformation #9

Closed thekid closed 9 years ago

thekid commented 9 years ago

If the constructor consists solely of assignments, you can include the Constructor trait and remove it. The parameters will be declared in the order the fields are declared: top to bottom, left to right in the source code.

Writing this:
namespace example;

use lang\partial\Constructor;

class Author extends \lang\Object {
  use Author\including\Constructor;

  private $handle, $name;
}
...is equivalent to:
namespace example;

class Author extends \lang\Object {
  private $handle, $name;

  public function __construct($handle, $name) {
    $this->handle= $handle;
    $this->name= $name;
  }
}
thekid commented 9 years ago

No typechecking is performed, but this may be done with a later pull request. See also #6