Skip to content

Implement unchecked types#156

Closed
thekid wants to merge 2 commits intomasterfrom
feature/unchecked-types
Closed

Implement unchecked types#156
thekid wants to merge 2 commits intomasterfrom
feature/unchecked-types

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