Ratings | | Unique User Downloads | | Download Rankings |
Not yet rated by the users | | Total: 36 | | All time: 10,706 This week: 189 |
|
Description | | Author |
This package can make class function calls invoke strict versions.
It provides a trait that can be used by any class, so when missing functions of the class are called, it can forward the calls to functions with the prefix strict, so PHP 7 based strict type checking of the parameters values passed to the class is performed. Innovation Award
 June 2020
Number 9 |
PHP 7 introduced the possibility to impose stricter restrictions to the types of the values passed or returned by class functions.
This package provides a simple trait that forces calling stricter versions of PHP class functions, even if applications call past versions of class versions that did not used to be stricter.
Manuel Lemos |
| |
 |
|
Innovation award
 Nominee: 28x
Winner: 1x |
|
Details
Stern

Stern lets you built type-safe PHP projects, even if your project's users aren't writing type-safe code.
Requires PHP 7+
Usage
Using Stern is simply:
-
Make your class use the `SternTrait`.
-
Rename your methods from `whateverName` to `strictWhateverName`.
-
Enjoy strict-typing whether your users like it or not.
Example
<?php
declare(strict_types=1);
namespace YourVendor\YourNamespace;
class YourClassThatUsesStrictTypes
{
+ use \ParagonIE\Stern\SternTrait;
/.../
- public function foo(string $param = ''): bool
+ public function strictFoo(string $param = ''): bool
{
}
}
Docblock Usability
For better usability (especially with type-aware IDEs like PHPStorm), make sure
you use @method
docblocks.
<?php
declare(strict_types=1);
namespace YourVendor\YourNamespace;
+ /
+ * @method bool foo(string $param = '')
+ */
class YourClassThatUsesStrictTypes
{
+ use \ParagonIE\Stern\SternTrait;
/.../
- public function foo(string $param = ''): bool
+ public function strictFoo(string $param = ''): bool
{
}
}
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.