PHPackages                             ffi/scalar-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ffi/scalar-utils

Abandoned → [ffi/scalar-utils](/?search=ffi%2Fscalar-utils)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

ffi/scalar-utils
================

PHP FFI Scalar Utilities

1.0.2(3y ago)72.1kMITPHPPHP ^7.4|^8.0

Since Nov 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/php-ffi/scalar-utils)[ Packagist](https://packagist.org/packages/ffi/scalar-utils)[ RSS](/packages/ffi-scalar-utils/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

FFI Scalar Utils
================

[](#ffi-scalar-utils)

 [![PHP 8.1+](https://camo.githubusercontent.com/900c5b8e9ee48baea04cfe5d109eb03b3fab6228988a9b942868ca8fa282c541/68747470733a2f2f706f7365722e707567782e6f72672f6666692f7363616c61722d7574696c732f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/ffi/scalar-utils) [![Latest Stable Version](https://camo.githubusercontent.com/0a935605978483c8344b1a24e32c45ec9d288ec075000b1387b0cfd04dcd9546/68747470733a2f2f706f7365722e707567782e6f72672f6666692f7363616c61722d7574696c732f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/ffi/scalar-utils) [![Latest Unstable Version](https://camo.githubusercontent.com/66921640b68db435d54f5a571ff47618806cc0f96a8112b77fbbbccd9dd03cfe/68747470733a2f2f706f7365722e707567782e6f72672f6666692f7363616c61722d7574696c732f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/ffi/scalar-utils) [![Total Downloads](https://camo.githubusercontent.com/30edd92ec1ddde84230923088f637d4f49f8c64d77c985bd28fb1ad6a0dbb361/68747470733a2f2f706f7365722e707567782e6f72672f6666692f7363616c61722d7574696c732f646f776e6c6f6164733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/ffi/scalar-utils) [![License MIT](https://camo.githubusercontent.com/b0ea4ea09bc4fbddc772790a6dca203322729a0b5ea8e5e34b3aeb9e1952b497/68747470733a2f2f706f7365722e707567782e6f72672f6666692f7363616c61722d7574696c732f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/php-ffi/scalar-utils/master/LICENSE.md)

 [![](https://github.com/php-ffi/scalar-utils/workflows/build/badge.svg)](https://github.com/php-ffi/scalar-utils/actions)

A set of util methods to interact with PHP and C scalar types.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- ext-ffi

Installation
------------

[](#installation)

Library is available as composer repository and can be installed using the following command in a root of your project.

```
$ composer require ffi/scalar-utils
```

Usage
-----

[](#usage)

### PHP To C Marshalling

[](#php-to-c-marshalling)

```
use FFI\Scalar\Type;

Type::int8(42);                 // object CData { cdata: 42 }
Type::int8Array([1, 2, 3]);     // object CData { cdata: [1, 2, 3] }
Type::uint8(42);                // object CData { cdata: 42 }
Type::uint8Array([1, 2, 3]);    // object CData { cdata: [1, 2, 3] }

Type::int16(42);                // object CData { cdata: 42 }
Type::int16Array([1, 2, 3]);    // object CData { cdata: [1, 2, 3] }
Type::uint16(42);               // object CData { cdata: 42 }
Type::uint16Array([1, 2, 3]);   // object CData { cdata: [1, 2, 3] }

Type::int32(42);                // object CData { cdata: 42 }
Type::int32Array([1, 2, 3]);    // object CData { cdata: [1, 2, 3] }
Type::uint32(42);               // object CData { cdata: 42 }
Type::uint32Array([1, 2, 3]);   // object CData { cdata: [1, 2, 3] }

Type::int64(42);                // object CData { cdata: 42 }
Type::int64Array([1, 2, 3]);    // object CData { cdata: [1, 2, 3] }
Type::uint64(42);               // object CData { cdata: 42 }
Type::uint64Array([1, 2, 3]);   // object CData { cdata: [1, 2, 3] }

Type::short(42);                // object CData { cdata: 42 }
Type::shortArray([1, 2, 3]);    // object CData { cdata: [1, 2, 3] }
Type::ushort(42);               // object CData { cdata: 42 }
Type::ushortArray([1, 2, 3]);   // object CData { cdata: [1, 2, 3] }

Type::int(42);                  // object CData { cdata: 42 }
Type::intArray([1, 2, 3]);      // object CData { cdata: [1, 2, 3] }
Type::uint(42);                 // object CData { cdata: 42 }
Type::uintArray([1, 2, 3]);     // object CData { cdata: [1, 2, 3] }

Type::long(42);                  // object CData { cdata: 42 }
Type::longArray([1, 2, 3]);      // object CData { cdata: [1, 2, 3] }
Type::ulong(42);                 // object CData { cdata: 42 }
Type::ulongArray([1, 2, 3]);     // object CData { cdata: [1, 2, 3] }

Type::float(42);                    // object CData { cdata: 42.0 }
Type::floatArray([1, 2, 3]);        // object CData { cdata: [1.0, 2.0, 3.0] }

Type::double(42);                   // object CData { cdata: 42.0 }
Type::doubleArray([1, 2, 3]);       // object CData { cdata: [1.0, 2.0, 3.0] }

Type::longDouble(42);               // object CData { cdata: 42.0 }
Type::longDoubleArray([1, 2, 3]);   // object CData { cdata: [1.0, 2.0, 3.0] }

Type::bool(true);                       // object CData { cdata: true }
Type::boolArray([true, false, true]);   // object CData { cdata: [true, false, true] }

Type::char('c');                    // object CData { cdata: 'c' }
Type::charArray(['a', 'b', 'c']);   // object CData { cdata: ['a', 'b', 'c'] }

Type::string('hi');                 // object CData { cdata: ['h', 'i', '\0'] }
Type::stringArray(['a', 'b']);      // object CData { cdata: [['a' '\0'], ['b', '\0']] }

Type::wideString('hi');             // object CData { cdata: ['h', 'i', '\0\0'] }
Type::wideStringArray(['a', 'b']);  // object CData { cdata: [['a' '\0\0'], ['b', '\0\0']] }

// Direct API
Type::create($ffi->type('example'), $value); // object CData { cdata: ... }
Type::array($ffi->type('example'), [$value]); // object CData { cdata: [ ... ] }
```

### C To PHP Marshalling

[](#c-to-php-marshalling)

```
use FFI\Scalar\Type;

Type::toString($cdata);     // string(x) "..."
Type::toWideString($cdata); // string(x) "..."
Type::toInt($cdata);        // int(x)
Type::toFloat($cdata);      // float(x)
Type::toBool($cdata);       // bool(x)
Type::toArray($cdata);      // array(...)
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~106 days

Total

5

Last Release

1233d ago

Major Versions

0.2.0 → 1.0.02021-11-03

PHP version history (2 changes)0.1.0PHP &gt;=7.4

1.0.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (8 commits)")

---

Tags

helpersutilsupportscalarffi

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ffi-scalar-utils/health.svg)

```
[![Health](https://phpackages.com/badges/ffi-scalar-utils/health.svg)](https://phpackages.com/packages/ffi-scalar-utils)
```

###  Alternatives

[padosoft/support

agnostic helpers to use as foundation in packages and other project

5117.0k5](/packages/padosoft-support)[prologue/support

Prologue Support is an extension for Illuminate Support

1616.8k](/packages/prologue-support)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
