{"id":16675198,"url":"https://github.com/rikudousage/scalar-objects","last_synced_at":"2026-04-21T22:03:43.239Z","repository":{"id":62535873,"uuid":"63707065","full_name":"RikudouSage/scalar-objects","owner":"RikudouSage","description":null,"archived":false,"fork":false,"pushed_at":"2019-08-27T15:21:44.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-19T21:47:29.746Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RikudouSage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-19T15:39:39.000Z","updated_at":"2019-08-27T15:21:46.000Z","dependencies_parsed_at":"2022-11-02T15:15:57.381Z","dependency_job_id":null,"html_url":"https://github.com/RikudouSage/scalar-objects","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RikudouSage%2Fscalar-objects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RikudouSage%2Fscalar-objects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RikudouSage%2Fscalar-objects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RikudouSage%2Fscalar-objects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RikudouSage","download_url":"https://codeload.github.com/RikudouSage/scalar-objects/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243337978,"owners_count":20275395,"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-10-12T12:45:51.447Z","updated_at":"2025-12-29T22:05:09.422Z","avatar_url":"https://github.com/RikudouSage.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scalar types as objects for php\n\nThis php library requires php extension from \u003chttps://github.com/nikic/scalar_objects\u003e.\n\n## Installation\n\nRun `composer require rikudou/scalar-objects`.\n\n## Usage\n\nThe handlers are automatically registered when you include composer\nautoload. That means you can use it immediately with no configuration.\n\nSince IDEs don't understand the syntax, there are typehint classes\navailable to help you.\n\n## Examples\n```php\n\u003c?php\n\nuse Rikudou\\ScalarObjects\\TypeHint\\IntegerTypehint;\nuse Rikudou\\ScalarObjects\\TypeHint\\StringTypehint;\n\nrequire_once \"vendor/autoload.php\";\n\n/** @var IntegerTypehint|int $num1 */\n$num1 = 5;\n/** @var StringTypehint|string $num2 */\n$num2 = \"10\";\n\n// the two variables are not actually objects, the typehints\n// are just for IDE completion\n\nvar_dump($num1-\u003eisInt()); // bool(true)\nvar_dump($num2-\u003eisString()); // bool(true)\nvar_dump($num2-\u003eisNumeric()); // bool(true)\nvar_dump($num2-\u003eisNumber()); // bool(false) - isNumber() returns true only for int and float\n\nvar_dump($num1-\u003etoString()-\u003elength()); // int(1)\n\n/** @var StringTypehint $string */\n$string = \"This is a test string\";\n\nvar_dump($string-\u003elength()); // int(21);\nvar_dump($string-\u003ecapitalize()); // string(21) \"This Is A Test String\"\nvar_dump($string-\u003ecaseInsensitiveCompare(\"this Is a TESt STRInG\")); // int(0)\nvar_dump($string-\u003etoUpper()); // string(21) \"THIS IS A TEST STRING\"\nvar_dump($string-\u003etoLower()); //string(21) \"this is a test string\"\n\n```\n\nAs you can see, you can use the scalar values as objects.\n\nBut you can still use them as regular scalar types.\n\n```php\n\u003c?php\n\nuse Rikudou\\ScalarObjects\\TypeHint\\IntegerTypehint;\nuse Rikudou\\ScalarObjects\\TypeHint\\StringTypehint;\n\nrequire_once __DIR__.\"/vendor/autoload.php\";\n\n/** @var StringTypehint|string $string */\n$string = \"test\";\n$string .= \"test\"; // works without a problem\nvar_dump($string); // string(8) \"testtest\"\n\n/** @var IntegerTypehint|int $int1 */\n$int1 = 5;\n/** @var IntegerTypehint|int $int2 */\n$int2 = -10;\n/** @var IntegerTypehint|int $int3 */\n$int3 = \"-15\";\n\nvar_dump($int1 + $int2-\u003eabs()); // int(15)\nvar_dump($int1 + $int2); // int(-5)\nvar_dump($int1 + $int2 + $int3-\u003etoInt()-\u003eabs()); // int(10)\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frikudousage%2Fscalar-objects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frikudousage%2Fscalar-objects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frikudousage%2Fscalar-objects/lists"}