{"id":16915877,"url":"https://github.com/tysonandre/var_representation","last_synced_at":"2025-03-22T10:32:40.592Z","repository":{"id":47753023,"uuid":"377659764","full_name":"TysonAndre/var_representation","owner":"TysonAndre","description":"var_representation() : readable alternative to var_export() in PHP","archived":false,"fork":false,"pushed_at":"2024-08-11T17:48:19.000Z","size":126,"stargazers_count":7,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T10:45:47.909Z","etag":null,"topics":["pecl","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TysonAndre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-17T00:17:17.000Z","updated_at":"2024-10-01T14:48:52.000Z","dependencies_parsed_at":"2024-10-28T13:16:01.296Z","dependency_job_id":"26f85913-34cc-4f36-949c-33b7cb6cc87f","html_url":"https://github.com/TysonAndre/var_representation","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TysonAndre%2Fvar_representation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TysonAndre%2Fvar_representation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TysonAndre%2Fvar_representation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TysonAndre%2Fvar_representation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TysonAndre","download_url":"https://codeload.github.com/TysonAndre/var_representation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244944378,"owners_count":20536290,"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":["pecl","php"],"created_at":"2024-10-13T19:23:15.432Z","updated_at":"2025-03-22T10:32:40.322Z","avatar_url":"https://github.com/TysonAndre.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# var\\_representation() : readable alternative to var\\_export()\n\n## Introduction\n\nThis extension adds a function\n`var_representation(mixed $value, int $flags = 0): string` to convert a\nvariable to a string in a way that fixes the shortcomings of `var_export()`\n\n[![Build Status](https://github.com/TysonAndre/var_representation/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/TysonAndre/var_representation/actions/workflows/main.yml?query=branch%3Amain)\n[![Build Status (Windows)](https://ci.appveyor.com/api/projects/status/9gq4nk1cwmgn88ye?svg=true)](https://ci.appveyor.com/project/TysonAndre/var-representation)\n\n## Installation\n\nThis extension requires php 7.2 or newer.\n\n```sh\npecl install var_representation\n```\n\nOn windows, see https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2 instead\n\n## Polyfill\n\n`composer.phar require tysonandre/var_representation_polyfill` can be used to install a less efficient polyfill:\nhttps://packagist.org/packages/TysonAndre/var_representation_polyfill\n\n## Usage\n\n```php\n// uses short arrays, and omits array keys if array_is_list() would be true\nphp \u003e echo var_representation(['a','b']);\n[\n  'a',\n  'b',\n]\n\n// can dump everything on one line.\nphp \u003e echo var_representation(['a', 'b', 'c'], VAR_REPRESENTATION_SINGLE_LINE);\n['a', 'b', 'c']\n\nphp \u003e echo var_representation(\"uses double quotes: \\$\\\"'\\\\\\n\");\n\"uses double quotes: \\$\\\"'\\\\\\n\"\n\n// Can disable the escaping of control characters\n// (e.g. if the return value needs to be escaped again)\nphp \u003e echo var_representation(\"has\\nnewlines\", VAR_REPRESENTATION_UNESCAPED);\n'has\nnewlines'\nphp \u003e echo json_encode(\"uses single quotes:\\0\\r\\n\\$\\\"'\\\\\");\n\"uses single quotes:\\u0000\\r\\n$\\\"'\\\\\"\nphp \u003e echo json_encode(var_representation(\"uses single quotes:\\0\\r\\n\\$\\\"'\\\\\",\n                                          VAR_REPRESENTATION_UNESCAPED));\n\"'uses single quotes:\\u0000\\r\\n$\\\"\\\\'\\\\\\\\'\"\n```\n\n## Documentation\n\nRefer to https://wiki.php.net/rfc/readable_var_representation for details such as what characters are escaped.\nAlso see the section [Differences from `var_export`](#differences-from-var_export).\n\n## Background information\n\nIt is inconvenient to work with the representation of *var\\_export()* in many\nways, especially since that function was introduced in php 4.2.0 and\npredates both namespaces and the short `[]` array syntax. However,\nbecause the output format of `var_export()` is depended upon in php's\nown unit tests, tests of PECL modules, and the behavior or unit tests of\nvarious applications written in PHP, changing `var_export` itself may\nbe impractical.\n\nProposals to add alternatives better to var_export to php itself\n[have been declined](https://wiki.php.net/rfc/readable_var_representation)\n\n## Differences from var_export\n\n`var_representation` has the following differences from `var_export`:\n\n- Escape control characters including tabs, newlines, etc.,\n  unlike `var_export()`/`var_dump()`.\n- Unconditionally return a string instead of printing to standard output.\n- Use `null` instead of `NULL`. The former is recommended by more coding guidelines such as [such as PSR-2](https://www.php-fig.org/psr/psr-2/).\n- Change the way indentation is done for arrays/objects. Always add 2\n  spaces for every level of arrays, never 3 in objects, and put the\n  array start on the same line as the key for arrays and objects)\n- Render lists as `\"['item1']\"` rather than `\"array(\\n 0 =\u003e 'item1',\\n)\"`\n- Always render empty lists on a single line instead of two lines.\n- Prepend `\\` to class names so that generated code snippets can be\n  used in namespaces without any issues.\n\n  (Note: `var_export` also started prepending `\\` to class names in php 8.2)\n- Support the bit flag `VAR_REPRESENTATION_SINGLE_LINE=1` in a new\n  optional parameter `int $flags = 0` accepting a bitmask. If the\n  value of $flags includes this flags, `var_representation()` will\n  return a single-line representation for arrays/objects.\n- Support the bit flag `VAR_REPRESENTATION_UNESCAPED` to force\n  strings to be single quoted and avoid escaping any control characters other than `'` and `\\`\n  (e.g. newlines will not be escaped even with `VAR_REPRESENTATION_SINGLE_LINE`).\n\n  This may be useful when short representations are needed,\n  or if the return value is escaped again.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftysonandre%2Fvar_representation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftysonandre%2Fvar_representation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftysonandre%2Fvar_representation/lists"}