1. Go to this page and download the library: Download nejcc/php-datatypes library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nejcc / php-datatypes example snippets
namespace App\Http\Controllers;
use Illuminate\Http\Request;use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32;use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt8;
class TestController
{
public UInt8 $user_id;
public Float32 $account_balance;
public function __invoke(Request $request)
{
// Validating and assigning UInt8 (ensures non-negative user ID)
$this->user_id = uint8($request->input('user_id'));
// Validating and assigning Float32 (ensures correct precision)
$this->account_balance = float32($request->input('account_balance'));
// Now you can safely use the $user_id and $account_balance knowing they are in the right range
dd([
'user_id' => $this->user_id->getValue(),
'account_balance' => $this->account_balance->getValue(),
]);
}
}
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8;use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt8;
$int8 = new Int8(-128); // Minimum value for Int8
echo $int8->getValue(); // -128
$uint8 = new UInt8(255); // Maximum value for UInt8
echo $uint8->getValue(); // 255
use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32;use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64;
$float32 = new Float32(3.14);
echo $float32->getValue(); // 3.14
$float64 = new Float64(1.7976931348623157e308); // Maximum value for Float64
echo $float64->getValue(); // 1.7976931348623157e308
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8;
$int1 = new Int8(50);
$int2 = new Int8(30);
$result = $int1->add($int2); // Performs addition
echo $result->getValue(); // 80
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.