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;
      }

 

 

 

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.

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....

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.