1

I've looked everywhere and cannot seem to figure this out. My issue is that I am trying to use the 'enum' for rank that is in my database but keep getting errors. What I have below I'd like to be able to display in a specific div depending on what rank a member is. This is what I have so far, where am I going wrong? If someone could shed some light on if this is even correct or what I need to do to make this work, I'd greatly appreciate it.

PHP:

class Rank
{
  // If no value is given during object construction this value is used
  const __default = 1;
  // Our enum values
  const Registered       = 1;
  const Legend           = 2;
  const Inactive         = 3;
  const Greenhorn        = 4;
  const FullMember       = 5;
  const JuniorAdmin      = 6;
  const SeniorAdmin      = 7;
  const Leader           = 8;
  const Founder          = 9;
  const OriginalFounder  = 10;
}

$registered     = new Rank(Rank::REGISTERED);
$legend         = new Rank(Rank::LEGEND);
$inactive           = new Rank(Rank::INACTIVE);
$greenhorn          = new Rank(Rank::GREENHORN);
$fullmember     = new Rank(Rank::FULLMEMBER);
$junioradmin        = new Rank(Rank::JUNIORADMIN);
$senioradmin        = new Rank(Rank::SENIORADMIN);
$leader         = new Rank(Rank::LEADER);
$founder            = new Rank(Rank::FOUNDER);
$originalfounder    = new Rank(Rank::ORIGINALFOUNDER);
$fail              = 1;

function responsibilities(Rank $rank)
{
  if (Rank::REGISTERED == $rank) {
    echo "Post something about being a registered member.\n";
  } elseif (Rank::LEGEND == $rank) {
    echo "Post something about being Legend.\n";
  } elseif (Rank::INACTIVE == $rank) {
    echo "Post something about being Inactive./n";
  } elseif (Rank::GREENHORN == $rank) {
    echo "Post something about being a Greenhorn./n";
  } elseif (Rank::FULLMEMBER == $rank) {
    echo "Post something about being a Full Member./n";
  } elseif (Rank::JUNIORADMIN == $rank) {
    echo "Post something about being a Junior Admin./n";
  } elseif (Rank::SENIORADMIN == $rank) {
    echo "Post something about being a Senior Admin./n";
  } elseif (Rank::LEADER == $rank) {
    echo "Post something about being a Leader./n";
  } elseif (Rank::FOUNDER == $rank) {
    echo "Post something about being a Founder./n";
  } elseif (Rank::ORIGINALFOUNDER == $rank) {
    echo "Post something about being an Original Founder./n";
  }
}

responsibilities($registered);
responsibilities($legend);
responsibilities($inactive);
responsibilities($greenhorn);
responsibilities($fullmember);
responsibilities($junioradmin);
responsibilities($senioradmin);
responsibilities($leader);
responsibilities($founder);
responsibilities($originalfounder);

responsibilities($fail);

HTML:

<p><?php echo $rank ?></p>
user2732875
  • 269
  • 5
  • 15

1 Answers1

1

It looks like you are trying to use the SplEnum class to make an enum. In order to have such an enum, you need your enum class to extend the SplEnum abstract class.

class Fruit extends SplEnum
{
    const __default = self::Apple; // default value; could also be __default = 0;
    // values
    const Apple = 0;
    const Orange = 1;
}

I haven't tested it, but I'm fairly certain that constants in an enum are case-sensitive. That is, if you define an enum Fruit like above, you can use Fruit::Orange but not Fruit::ORANGE. I think the normal convention is to use all UPPERCASE, since they are constants.