Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement unchecked types #156

Closed
wants to merge 2 commits into from
Closed

Implement unchecked types #156

wants to merge 2 commits into from

Conversation

thekid
Copy link
Member

@thekid thekid commented Feb 12, 2023

These types only end up in the type meta information.

class Fixture {
  public function verified(string $param) { }
  public function unchecked(@string $param) { }
}

$f= new Fixture();
$t->verified(null);  // Exception
$t->unchecked(null); // Works

This is equivalent to using API docs only; however, the syntax is checked, whereas in the following, it isn't:

class Fixture {
  public function verified(string $param) { }

  /** @param string $param */
  public function unchecked($param) { }
}

In reflection, a parameter type is available but not reported as a constraint.

use lang\Reflection;

$r= Reflection::type(Fixture::class);

// Verified method
$c= $r->method('verified')->parameter(0)->constraint();
$c->type();    // Primitive::$STRING
$c->present(); // true

// Unchecked method
$c= $r->method('unchecked')->parameter(0)->constraint();
$c->type();    // Primitive::$STRING
$c->present(); // false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant