Download the PHP package nejcc/php-datatypes without Composer
On this page you can find all versions of the php package nejcc/php-datatypes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nejcc/php-datatypes
More information about nejcc/php-datatypes
Files in nejcc/php-datatypes
Package php-datatypes
Short Description PHP Data types
License MIT
Homepage https://github.com/nejcc/php-datatypes
Informations about the package php-datatypes
Introducing PHP Datatypes: A Strict and Safe Way to Handle Primitive Data Types
I'm excited to share my latest PHP package, PHP Datatypes. This library introduces a flexible yet strict way of handling primitive data types like integers, floats, and strings in PHP. It emphasizes type safety and precision, supporting operations for signed and unsigned integers (Int8, UInt8, etc.) and various floating-point formats (Float32, Float64, etc.).
With PHP Datatypes, you get fine-grained control over the data you handle, ensuring your operations stay within valid ranges. It's perfect for anyone looking to avoid common pitfalls like overflows, division by zero, and unexpected type juggling in PHP.
Installation
You can install the package via composer:
Usage
Below are examples of how to use the basic integer and float classes in your project.
This approach has a few key benefits:
-
Type Safety: By explicitly defining the data types like UInt8, you're eliminating the risk of invalid values sneaking into your application. For example, enforcing unsigned integers ensures that the value remains within valid ranges, offering a safeguard against unexpected data inputs.
-
Precision: Especially with floating-point numbers, handling precision can be tricky in PHP due to how it manages floats natively. By offering precise types such as Float32 or Float64, we're giving developers the control they need to maintain consistency in calculations.
-
Range Safeguards: By specifying exact ranges, you can prevent issues like overflows or underflows that often go unchecked in dynamic typing languages like PHP.
- Readability and Maintenance: Explicit data types improve code readability. When a developer reads your code, they instantly know what type of value is expected and the constraints around that value. This enhances long-term maintainability.
Laravel example
here's how it can be used in practice across different types, focusing on strict handling for both integers and floats:
Here, we're not only safeguarding user IDs but also handling potentially complex floating-point operations, where precision is critical. This could be especially beneficial for applications in fields like finance or analytics where data integrity is paramount.
PHP examples
Integers
Floats
Arithmetic Operations
ROAD MAP
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
PHP Package Boilerplate
This package was generated using the PHP Package Boilerplate by Beyond Code.
All versions of php-datatypes with dependencies
ext-bcmath Version *
ext-ctype Version *