{"id":18309798,"url":"https://github.com/yinfuyuan/php-enum","last_synced_at":"2025-04-05T17:33:03.451Z","repository":{"id":57040317,"uuid":"264996805","full_name":"yinfuyuan/php-enum","owner":"yinfuyuan","description":"PHPEnum is an enumeration class library for PHP developers. The idea comes from Java enumeration, and using the PHP features to implement single-value enumeration and multi-value enumeration. ","archived":false,"fork":false,"pushed_at":"2021-02-18T08:39:51.000Z","size":87,"stargazers_count":70,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-20T20:04:07.973Z","etag":null,"topics":["enum","enumeration","php-enum"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yinfuyuan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"yinfuyuan","custom":"https://github.com/yinfuyuan/php-enum"}},"created_at":"2020-05-18T16:25:56.000Z","updated_at":"2023-12-30T07:35:20.000Z","dependencies_parsed_at":"2022-08-23T23:30:39.933Z","dependency_job_id":null,"html_url":"https://github.com/yinfuyuan/php-enum","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/yinfuyuan%2Fphp-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinfuyuan%2Fphp-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinfuyuan%2Fphp-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinfuyuan%2Fphp-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yinfuyuan","download_url":"https://codeload.github.com/yinfuyuan/php-enum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247375652,"owners_count":20929073,"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":["enum","enumeration","php-enum"],"created_at":"2024-11-05T16:12:26.899Z","updated_at":"2025-04-05T17:32:58.435Z","avatar_url":"https://github.com/yinfuyuan.png","language":"PHP","readme":"# PHP Enum\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/phpenum/phpenum.svg?style=for-the-badge)](https://packagist.org/packages/phpenum/phpenum)\n[![License](https://img.shields.io/github/license/yinfuyuan/php-enum?style=for-the-badge)](https://github.com/yinfuyuan/php-enum/blob/master/LICENSE)\n![Postcardware](https://img.shields.io/badge/Postcardware-%F0%9F%92%8C-197593?style=for-the-badge)\n\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/phpenum/phpenum?style=flat-square)](https://packagist.org/packages/phpenum/phpenum)\n[![Build Status](https://img.shields.io/github/workflow/status/yinfuyuan/php-enum/tests?label=tests\u0026style=flat-square)](https://github.com/yinfuyuan/php-enum/actions?query=workflow%3Atests)\n[![Total Downloads](https://img.shields.io/packagist/dt/phpenum/phpenum.svg?style=flat-square)](https://packagist.org/packages/phpenum/phpenum)\n\nPHPEnum is an enumeration class library for PHP developers. The idea comes from [Java enumeration](https://docs.oracle.com/javase/8/docs/api/java/lang/Enum.html), and using the PHP features to implement single-value enumeration and multi-value enumeration. PHPEnum runs in most PHP applications.\n\n### Installation\n\n    composer require phpenum/phpenum\n\n### Getting Started\n\nUsing PhpEnum is very similar to using Java Enum, For example, define an enumeration representing gender.\n\nIn Java:\n\n    public enum GenderEnum {\n        MALE(1, \"male\"),\n        FEMALE(2, \"female\");\n    \n        private Integer id;\n        private String name;\n    \n        GenderEnum(Integer id, String name) {\n            this.id = id;\n            this.name = name;\n        }\n    \n        public Integer getId() {\n            return id;\n        }\n    \n        public String getName() {\n            return name;\n        }\n    }\n\nIn PHP:\n\n    class GenderEnum extends \\PhpEnum\\Enum\n    {\n        const MALE = [1, 'male'];\n        const FEMALE = [2, 'female'];\n    \n        private $id;\n        private $name;\n    \n        protected function construct($id, $name)\n        {\n            $this-\u003eid = $id;\n            $this-\u003ename = $name;\n        }\n    \n        public function getId()\n        {\n            return $this-\u003eid;\n        }\n        \n        public function getName()\n        {\n            return $this-\u003ename;\n        }\n    }\n\nYou'll also find a lot of similarities when using enumerations\n\nIn Java:\n\n    GenderEnum.values(); // enum instance array\n    GenderEnum.valueOf(\"FEMALE\"); // enum instance\n    GenderEnum.MALE.equals(GenderEnum.valueOf(\"MALE\")); // true\n    GenderEnum.MALE.name(); // MALE\n    GenderEnum.MALE.ordinal(); // 0\n    GenderEnum.MALE.toString(); // MALE\n    GenderEnum.MALE.getId(); // 1\n    GenderEnum.MALE.getName(); // male\n\nIn PHP:\n\n    GenderEnum::values(); // enum instance array\n    GenderEnum::valueOf('FEMALE'); // enum instance\n    GenderEnum::MALE()-\u003eequals(GenderEnum::valueOf('MALE')); // true\n    GenderEnum::MALE()-\u003ename(); // MALE\n    GenderEnum::MALE()-\u003eordinal(); // 0\n    (string)GenderEnum::MALE(); // MALE\n    GenderEnum::MALE()-\u003egetId(); // 1\n    GenderEnum::MALE()-\u003egetName(); // male\n\nNot only that, PhpEnum also provides advanced functionality in subclasses\n\n    GenderEnum::MALE()-\u003eidEquals(1); // true\n    GenderEnum::MALE()-\u003eNameEquals('male'); // true\n    GenderEnum::containsId(1); // 1\n    GenderEnum::containsName('male'); // 1\n    GenderEnum::ofId(1); // enum instance\n    GenderEnum::ofName('male'); // enum instance\n\n### Documentation\n\nPhpEnum supports PHP version 5.6+. The documentation for PHPEnum is available on the [Github wiki](https://github.com/yinfuyuan/php-enum/wiki).\n\n### License\n\nThe PHPEnum is open-sourced software licensed under the [GPL-3.0 license](https://github.com/yinfuyuan/php-enum/blob/master/LICENSE).\n","funding_links":["https://github.com/sponsors/yinfuyuan","https://github.com/yinfuyuan/php-enum"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyinfuyuan%2Fphp-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyinfuyuan%2Fphp-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyinfuyuan%2Fphp-enum/lists"}