Jump to content

[SOLVED] I am getting an undefined variable error


co.ador

Recommended Posts

 

 

Notice: Undefined variable: classes in C:\wamp\www\shoes\stores\classes\rating.class.php on line 160

 

private static function ShowStars($varStars)
      {
        // Select the Number of Stars Class
        switch ($varStars)
        {
          case 1:
            $classes .= "onestar";
            break;
          case 2:
            $classes .= "twostar";
            break;
          case 3:
            $classes .= "threestar";
            break;
          case 4:
            $classes .= "fourstar";
            break;
          case 5:
            $classes .= "fivestar"; // line 160
            break;
          default:
            $classes .= "nostar";
            break;
        }
        
        return $classes;
      }

 

 

 

Link to comment
Share on other sites

Hi there :-)

 

You are trying to append to the variable $classes before it has been initialised.

 

Either change the append operators to assignment operators (.= becomes =), or initialise the variable before the start of the switch statement ($classes = ''; ).

 

IMO, the first idea makes more sense as there is no reason to be appending to $classes in this case as it contains no data to begin with.

Link to comment
Share on other sites

Problem solved I tried both method worked.

 

1- changing the append operators to assignment operators

 

2- and initializing the variable.

 

I initialized the $classes=''; inside the switch statement and it didn't worked then I tried outside and it did worked. Then I read your post and I realized you stated to initialized before the star switch statement.  hard head :) thank bro..

 

Problem solved...

 

Hey don't forget to initialise is written with an z  :D Lol....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.