3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum ProductCategories: string { case A = 'A'; case B = 'B'; case C = 'C'; case D = 'D'; } interface ProductCategoryProviderInterface { public function getLocalCategoryId(ProductCategories $category): ?string; } class A implements ProductCategoryProviderInterface { public function getLocalCategoryId(ProductCategories $category): ?string { return match ($category) { ProductCategories::A => '1', ProductCategories::B => '2', default => null, }; } } class B implements ProductCategoryProviderInterface { public function getLocalCategoryId(ProductCategories $category): ?string { return match ($category) { ProductCategories::A => 'cat_a', ProductCategories::B => 'cat_B', default => null, }; } } echo (new A())->getLocalCategoryId(ProductCategories::A) . "\n"; // 1 echo (new B())->getLocalCategoryId(ProductCategories::A) . "\n"; // cat_a echo (new A())->getLocalCategoryId(ProductCategories::B) . "\n"; // 2 echo (new B())->getLocalCategoryId(ProductCategories::B) . "\n"; // cat_b echo (new A())->getLocalCategoryId(ProductCategories::C) . "\n"; // null
Output for git.master, git.master_jit
1 cat_a 2 cat_B

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
55.19 ms | 405 KiB | 5 Q