{"id":18397297,"url":"https://github.com/php-ffi/scalar-utils","last_synced_at":"2025-04-07T04:33:08.881Z","repository":{"id":53210333,"uuid":"398540324","full_name":"php-ffi/scalar-utils","owner":"php-ffi","description":"PHP FFI Scalar Utilities","archived":true,"fork":false,"pushed_at":"2023-01-01T13:54:50.000Z","size":18,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T06:24:16.161Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-ffi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-21T11:27:20.000Z","updated_at":"2024-12-16T13:46:44.000Z","dependencies_parsed_at":"2023-01-31T23:00:33.378Z","dependency_job_id":null,"html_url":"https://github.com/php-ffi/scalar-utils","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fscalar-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fscalar-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fscalar-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fscalar-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-ffi","download_url":"https://codeload.github.com/php-ffi/scalar-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595360,"owners_count":20963939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:16:38.939Z","updated_at":"2025-04-07T04:33:03.867Z","avatar_url":"https://github.com/php-ffi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FFI Scalar Utils\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/scalar-utils\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/scalar-utils/require/php?style=for-the-badge\" alt=\"PHP 8.1+\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/scalar-utils\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/scalar-utils/version?style=for-the-badge\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/scalar-utils\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/scalar-utils/v/unstable?style=for-the-badge\" alt=\"Latest Unstable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/scalar-utils\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/scalar-utils/downloads?style=for-the-badge\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://raw.githubusercontent.com/php-ffi/scalar-utils/master/LICENSE.md\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/scalar-utils/license?style=for-the-badge\" alt=\"License MIT\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/php-ffi/scalar-utils/actions\"\u003e\u003cimg src=\"https://github.com/php-ffi/scalar-utils/workflows/build/badge.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nA set of util methods to interact with PHP and C scalar types.\n\n## Requirements\n\n- PHP \u003e= 7.4\n- ext-ffi\n\n## Installation\n\nLibrary is available as composer repository and can be installed using the \nfollowing command in a root of your project.\n\n```sh\n$ composer require ffi/scalar-utils\n```\n\n## Usage\n\n### PHP To C Marshalling\n\n```php\nuse FFI\\Scalar\\Type;\n\nType::int8(42);                 // object CData\u003cint8_t\u003e { cdata: 42 }\nType::int8Array([1, 2, 3]);     // object CData\u003cint8_t[3]\u003e { cdata: [1, 2, 3] }\nType::uint8(42);                // object CData\u003cuint8_t\u003e { cdata: 42 }\nType::uint8Array([1, 2, 3]);    // object CData\u003cuint8_t[3]\u003e { cdata: [1, 2, 3] }\n\nType::int16(42);                // object CData\u003cint16_t\u003e { cdata: 42 }\nType::int16Array([1, 2, 3]);    // object CData\u003cint16_t[3]\u003e { cdata: [1, 2, 3] }\nType::uint16(42);               // object CData\u003cuint16_t\u003e { cdata: 42 }\nType::uint16Array([1, 2, 3]);   // object CData\u003cuint16_t[3]\u003e { cdata: [1, 2, 3] }\n\nType::int32(42);                // object CData\u003cint32_t\u003e { cdata: 42 }\nType::int32Array([1, 2, 3]);    // object CData\u003cint32_t[3]\u003e { cdata: [1, 2, 3] }\nType::uint32(42);               // object CData\u003cuint32_t\u003e { cdata: 42 }\nType::uint32Array([1, 2, 3]);   // object CData\u003cuint32_t[3]\u003e { cdata: [1, 2, 3] }\n\nType::int64(42);                // object CData\u003cint64_t\u003e { cdata: 42 }\nType::int64Array([1, 2, 3]);    // object CData\u003cint64_t[3]\u003e { cdata: [1, 2, 3] }\nType::uint64(42);               // object CData\u003cuint64_t\u003e { cdata: 42 }\nType::uint64Array([1, 2, 3]);   // object CData\u003cuint64_t[3]\u003e { cdata: [1, 2, 3] }\n\nType::short(42);                // object CData\u003csigned short int\u003e { cdata: 42 }\nType::shortArray([1, 2, 3]);    // object CData\u003csigned short int[3]\u003e { cdata: [1, 2, 3] }\nType::ushort(42);               // object CData\u003cunsigned short int\u003e { cdata: 42 }\nType::ushortArray([1, 2, 3]);   // object CData\u003cunsigned short int[3]\u003e { cdata: [1, 2, 3] }\n\nType::int(42);                  // object CData\u003csigned int\u003e { cdata: 42 }\nType::intArray([1, 2, 3]);      // object CData\u003csigned int[3]\u003e { cdata: [1, 2, 3] }\nType::uint(42);                 // object CData\u003cunsigned int\u003e { cdata: 42 }\nType::uintArray([1, 2, 3]);     // object CData\u003cunsigned int[3]\u003e { cdata: [1, 2, 3] }\n\nType::long(42);                  // object CData\u003csigned long int\u003e { cdata: 42 }\nType::longArray([1, 2, 3]);      // object CData\u003csigned long int[3]\u003e { cdata: [1, 2, 3] }\nType::ulong(42);                 // object CData\u003cunsigned long int\u003e { cdata: 42 }\nType::ulongArray([1, 2, 3]);     // object CData\u003cunsigned long int[3]\u003e { cdata: [1, 2, 3] }\n\nType::float(42);                    // object CData\u003cfloat\u003e { cdata: 42.0 }\nType::floatArray([1, 2, 3]);        // object CData\u003cfloat[3]\u003e { cdata: [1.0, 2.0, 3.0] }\n\nType::double(42);                   // object CData\u003cdouble\u003e { cdata: 42.0 }\nType::doubleArray([1, 2, 3]);       // object CData\u003cdouble[3]\u003e { cdata: [1.0, 2.0, 3.0] }\n\nType::longDouble(42);               // object CData\u003clong double\u003e { cdata: 42.0 }\nType::longDoubleArray([1, 2, 3]);   // object CData\u003clong double[3]\u003e { cdata: [1.0, 2.0, 3.0] }\n\nType::bool(true);                       // object CData\u003cbool\u003e { cdata: true }\nType::boolArray([true, false, true]);   // object CData\u003cbool[3]\u003e { cdata: [true, false, true] }\n\nType::char('c');                    // object CData\u003cchar\u003e { cdata: 'c' }\nType::charArray(['a', 'b', 'c']);   // object CData\u003cchar[3]\u003e { cdata: ['a', 'b', 'c'] }\n\nType::string('hi');                 // object CData\u003cchar[3]\u003e { cdata: ['h', 'i', '\\0'] }\nType::stringArray(['a', 'b']);      // object CData\u003cchar[2][2]\u003e { cdata: [['a' '\\0'], ['b', '\\0']] }\n\nType::wideString('hi');             // object CData\u003cwchar_t[3]\u003e { cdata: ['h', 'i', '\\0\\0'] }\nType::wideStringArray(['a', 'b']);  // object CData\u003cwchar_t[2][2]\u003e { cdata: [['a' '\\0\\0'], ['b', '\\0\\0']] }\n\n// Direct API\nType::create($ffi-\u003etype('example'), $value); // object CData\u003cexample\u003e { cdata: ... }\nType::array($ffi-\u003etype('example'), [$value]); // object CData\u003cexample[1]\u003e { cdata: [ ... ] }\n```\n\n### C To PHP Marshalling\n\n```php\nuse FFI\\Scalar\\Type;\n\nType::toString($cdata);     // string(x) \"...\"\nType::toWideString($cdata); // string(x) \"...\"\nType::toInt($cdata);        // int(x)\nType::toFloat($cdata);      // float(x)\nType::toBool($cdata);       // bool(x)\nType::toArray($cdata);      // array(...)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-ffi%2Fscalar-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-ffi%2Fscalar-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-ffi%2Fscalar-utils/lists"}