Hacker News new | ask | show | jobs
by bennyp101 1670 days ago
You can get some basic checking, but not type in arrays [1]. Maybe using attributes you could check if it is?

  class TFooOptions
  {
      public function __construct(
          public bool $enableFlag,
          public array $userIds = [],
      ) {
      }
  }

  $options = new TFooOptions(
      enableflags: true,
      userIds: [1,2,3]
  );

  new Foo('Bob', $options);
Or if just for IDE checking, you could use the @property docblock value on the class.

[1] https://wiki.php.net/rfc/arrayof