Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2020-06-26 (27 days ago)  | | Not yet rated by the users | | Total: 25 This week: 1 | | All time: 9,959 This week: 233 |
|
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
Nominee
Vote |
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: 20x
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.