class My_RedBean_SimpleModel extends RedBean_SimpleModel
{
public static function cast($instance): static
{
return $instance->box();
}
}
This lets you do something like:
$product = ModelProduct::cast($product);
which, in my editor, fixes type-hinting more reliably than anything else I tried.
I've also been using it to specify expected variables at the top of my templates (php files included inline with require), much like they are function arguments. It makes the templates fail early and loudly if they aren't passed the proper beans, and it was a simple way to get type hinting to work in those files.
This requires PHP 8.0 or greater.
This lets you do something like:
which, in my editor, fixes type-hinting more reliably than anything else I tried.
I've also been using it to specify expected variables at the top of my templates (php files included inline with
require
), much like they are function arguments. It makes the templates fail early and loudly if they aren't passed the proper beans, and it was a simple way to get type hinting to work in those files.