{"id":19324860,"url":"https://github.com/spatie/invade","last_synced_at":"2025-05-15T16:03:09.028Z","repository":{"id":38356553,"uuid":"458225846","full_name":"spatie/invade","owner":"spatie","description":"A PHP function to work with private properties and methods","archived":false,"fork":false,"pushed_at":"2025-05-12T05:32:56.000Z","size":540,"stargazers_count":320,"open_issues_count":3,"forks_count":17,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-12T06:33:47.748Z","etag":null,"topics":["consenting-adults","php"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","language":"PHP","has_issues":false,"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/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"spatie"}},"created_at":"2022-02-11T14:47:16.000Z","updated_at":"2025-05-12T05:32:52.000Z","dependencies_parsed_at":"2024-04-29T06:31:50.449Z","dependency_job_id":"e4d8c522-a15f-4ae1-bc69-ab81b1a6dc7a","html_url":"https://github.com/spatie/invade","commit_stats":{"total_commits":46,"total_committers":10,"mean_commits":4.6,"dds":0.7608695652173914,"last_synced_commit":"0ca2baf5c6461da39abfa167743e70327320b97f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":"spatie/package-skeleton-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Finvade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Finvade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Finvade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Finvade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/invade/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374400,"owners_count":22060609,"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":["consenting-adults","php"],"created_at":"2024-11-10T02:07:11.428Z","updated_at":"2025-05-15T16:03:08.988Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"/art/socialcard.png\" alt=\"Social Card of Invade\"\u003e\u003c/p\u003e\n\n# A PHP function to access private properties and methods\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/invade.svg?style=flat-square)](https://packagist.org/packages/spatie/invade)\n[![Tests](https://github.com/spatie/invade/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/spatie/invade/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/invade.svg?style=flat-square)](https://packagist.org/packages/spatie/invade)\n\nThis package offers an `invade` function that will allow you to read/write private properties of an object. It will also allow you to call private methods.\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/invade.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/invade)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/invade\n```\n\n## Usage\n\nImagine you have this class defined which has a private property and method.\n\n```php\nclass MyClass\n{\n    private string $privateProperty = 'private value';\n\n    private function privateMethod(): string\n    {\n        return 'private return value';\n    }\n}\n\n$myClass = new Myclass();\n```\n\nThis is how you can get the value of the private property using the `invade` function.\n\n```php\ninvade($myClass)-\u003eprivateProperty; // returns 'private value'\n```\n\nThe `invade` function also allows you to change private values.\n\n```php\ninvade($myClass)-\u003eprivateProperty = 'changed value';\ninvade($myClass)-\u003eprivateProperty; // returns 'changed value\n```\n\nUsing `invade` you can also call private functions.\n\n```php\ninvade($myClass)-\u003eprivateMethod(); // returns 'private return value'\n```\n\nFurther, you can also get and set private static class properties and call private static methods. Imagine having this class:\n\n```php\nclass MyClass\n{\n    private static string $privateStaticProperty = 'privateValue';\n\n    private static function privateStaticMethod(string $string, int $int): string\n    {\n        return 'private return value ' . $string . ' ' . $int;\n    }\n}\n```\n\nHere is how you get and set private class properties:\n\n```php\ninvade(MyClass::class)-\u003eget('privateStaticProperty'); // returns 'private value'\n\ninvade(MyClass::class)-\u003eset('privateStaticProperty', 'changedValue');\n\ninvade(MyClass::class)-\u003eget('privateStaticProperty'); // returns 'changedValue'\n```\n\nAnd this is how you call private static methods:\n\n```php\ninvade(MyClass::class)\n    -\u003emethod('privateStaticMethod')\n    -\u003ecall('foo', 123);\n\n// returns 'private return value foo 123'\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/spatie)\n- [All Contributors](../../contributors)\n\nAnd a special thanks to [Caneco](https://twitter.com/caneco) for the logo ✨\n\nThe [original idea](https://twitter.com/calebporzio/status/1492141967404371968) for the `invade` function came from [Caleb \"string king\" Porzio](https://twitter.com/calebporzio). We slightly polished the code that he created in [this commit on Livewire](https://github.com/livewire/livewire/pull/4649/files).\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Finvade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Finvade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Finvade/lists"}