3

Does anyone know for php AbstractEnumeration if there is any way to do another level underneath it?

so like...

const a = 'a';
const b = 'b';

But I have an optional parameter for a:

const a = 'a' => '=123'

I know this is probably going to end up as a hash table instead, but just wondering what interesting things I can do with php enums.

theamycode
  • 219
  • 3
  • 10

2 Answers2

1

PHP doesn't support native Enumerations.

You do something like:

abstract class ErrorCode
{
   const NOT_FOUND = 404;
   const OK = 200;
   // etc.

}

$error = ErrorCode::NOT_FOUND;

This won't work in PHP:

const a = 'a' => '=123'
Suraj K
  • 321
  • 3
  • 7
  • I've been using this: https://github.com/eloquent/enumeration But I like the latter idea. Thanks! I'll see if it works out. EDIT: php doesn't allow expressions in constant values – theamycode Jul 29 '14 at 15:02
0

you could serialize the object as an array:

# serialize data into an array
define ("a", serialize (array ("a" => 123)));

# use it wherever you want
$a = unserialize (a);
blurstream
  • 429
  • 3
  • 13