{"id":21433687,"url":"https://github.com/thomassquall/phputils","last_synced_at":"2026-05-18T18:39:11.207Z","repository":{"id":57068989,"uuid":"163536743","full_name":"ThomasSquall/PHPUtils","owner":"ThomasSquall","description":"Generic Utilities for PHP","archived":false,"fork":false,"pushed_at":"2019-08-23T09:22:29.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T06:41:13.459Z","etag":null,"topics":["array","json","php","utils","utils-library"],"latest_commit_sha":null,"homepage":null,"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/ThomasSquall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-29T19:45:32.000Z","updated_at":"2019-08-23T09:21:56.000Z","dependencies_parsed_at":"2022-08-24T10:20:40.161Z","dependency_job_id":null,"html_url":"https://github.com/ThomasSquall/PHPUtils","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasSquall%2FPHPUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasSquall%2FPHPUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasSquall%2FPHPUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasSquall%2FPHPUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThomasSquall","download_url":"https://codeload.github.com/ThomasSquall/PHPUtils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243945525,"owners_count":20372894,"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":["array","json","php","utils","utils-library"],"created_at":"2024-11-22T23:29:24.002Z","updated_at":"2026-05-18T18:39:11.152Z","avatar_url":"https://github.com/ThomasSquall.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Utils for php\n\n## List of available functions\n\n1) [array_to_object](#array_to_object)\n2) [json_to_object](#json_to_object)\n3) [parse_args](#parse_args)\n4) [get](#get)\n5) [dispose](#dispose)\n6) [is_cli](#is_cli)\n\n#### Other contained Repositories\n\n1) [String utils](https://github.com/ThomasSquall/PHPStringUtils)\n1) [File utils](https://github.com/ThomasSquall/PHPFileUtils)\n\n### array_to_object\n\n#### Description\n\nReturns an object out of an array.\nNote that only fields corresponding to the array keys will be returned.\n\n#### Definition\n\narray_to_object($array, $object)\n\nWhere:\n1) $array is the array to convert\n2) $object is the object or class to be returned\n3) $add_not_existing_properties is used to choose whether to add properties not defined in the class to the object\n\n#### Usage\n\n``` php\nclass Person {\n    public $name;\n    public $age;\n}\n\n$array = [\n    \"name\" =\u003e \"MyName\",\n    \"surname\" =\u003e \"MySurname\",\n    \"age\" =\u003e 27\n];\n\nprint_r(array_to_object($array, \"Person\"));\necho PHP_EOL;\nprint_r(array_to_object($array, \"Person\", true));\n```\n\nThis will print:\n\n``` sh\nPerson Object ( [name] =\u003e MyName [age] =\u003e 27 ) \nPerson Object ( [name] =\u003e MyName [age] =\u003e 27 [surname] =\u003e MySurname )\n```\n\n### json_to_object\n\n#### Description\n\nReturns an object out of a json string.\nNote that only fields corresponding to the json keys will be returned  unless you pass $add_not_existing_properties to true.\n\n#### Definition\n\njson_to_object($json, $object, $add_not_existing_properties = false)\n\nWhere:\n1) json is the json to convert\n2) $object is the object or class to be returned\n3) $add_not_existing_properties is used to choose whether to add properties not defined in the class to the object\n\n#### Usage\n\n``` php\nclass Person {\n    public $name;\n    public $age;\n}\n\n$json = '{\n    \"name\": \"MyName\",\n    \"surname\": \"MySurname\",\n    \"age\": 27\n}';\n\nprint_r(array_to_object($json, \"Person\"));\necho PHP_EOL;\nprint_r(array_to_object($json, \"Person\", true));\n```\n\nThis will print:\n\n``` sh\nPerson Object ( [name] =\u003e MyName [age] =\u003e 27 ) \nPerson Object ( [name] =\u003e MyName [age] =\u003e 27 [surname] =\u003e MySurname )\n```\n\n### parse_args\n\n#### Description\n\nBuild a new array out of the $options one with defaults values taken from $defaults when nothing is found.\n\n#### Definition\n\nparse_args($options, $defaults)\n\nWhere:\n1) $options is the array to be parsed and used to build the new array\n2) $defaults is the array containing default values to use when no correspondence is found\n\n#### Usage\n\n``` php\n$defaults = [\n    \"name\" =\u003e \"MyName\",\n    \"surname\" =\u003e \"MySurname\",\n    \"age\" =\u003e 27\n];\n\n$person = [\n    \"name\" =\u003e \"MyRealName\",\n    \"surname\" =\u003e \"MyRealSurname\"\n];\n\nprint_r(parse_args($person, $defaults));\n```\n\nThis will print:\n\n``` sh\nArray ( [name] =\u003e MyRealName [surname] =\u003e MyRealSurname [age] =\u003e 27 )\n```\n\n### get\n\n#### Description\nChecks if the provided value is empty and, if it is, the default value will be returned. The value itself will be returned otherwise.\n\n#### Definition\n\nget($value, $default = \"\")\n\nWhere:\n1) $value is the value to be checked to be empty or not\n2) $default is the value to pass in case the first is empty. Defaulted to empty string\n\n#### Usage\n\n``` php\n$value = \"\";\n\necho get($value, \"hello\");\n```\n\nThis will print:\n\n``` sh\nhello\n```\n\n### dispose\n\n#### Description\n\nDisposes any item.\n\n#### Definition\n\ndispose(\u0026$item)\n\nWhere:\n1) $item is the item to be disposes\n\n#### Usage\n\n``` php\n$array = [\n    \"Hello\",\n    \" \",\n    \"world\"\n];\n\ndispose($array);\n```\n\n### is_cli\n\n#### Description\n\nReturns true if the script is running in the cli or not.\n\n#### Definition\n\nis_cli()\n\n#### Usage\n\n``` php\nif (is_cli())\n    echo \"This script is running in the shell\";\nelse\n    echo \"This script is not running in the shell\";\n```\n\n## More utilities coming...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassquall%2Fphputils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomassquall%2Fphputils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassquall%2Fphputils/lists"}