co.ador Posted July 21, 2009 Share Posted July 21, 2009 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 https://forums.phpfreaks.com/topic/166872-solved-i-am-getting-an-undefined-variable-error/ Share on other sites More sharing options...
TomNomNom Posted July 21, 2009 Share Posted July 21, 2009 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 https://forums.phpfreaks.com/topic/166872-solved-i-am-getting-an-undefined-variable-error/#findComment-879869 Share on other sites More sharing options...
co.ador Posted July 21, 2009 Author Share Posted July 21, 2009 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 Lol.... Link to comment https://forums.phpfreaks.com/topic/166872-solved-i-am-getting-an-undefined-variable-error/#findComment-879894 Share on other sites More sharing options...
TomNomNom Posted July 22, 2009 Share Posted July 22, 2009 Glad I could be of service Hey don't forget to initialise is written with an z Lol.... Not in Britain it ain't ;-) Link to comment https://forums.phpfreaks.com/topic/166872-solved-i-am-getting-an-undefined-variable-error/#findComment-879902 Share on other sites More sharing options...
co.ador Posted July 22, 2009 Author Share Posted July 22, 2009 O Well! Languages! Link to comment https://forums.phpfreaks.com/topic/166872-solved-i-am-getting-an-undefined-variable-error/#findComment-879904 Share on other sites More sharing options...
co.ador Posted July 22, 2009 Author Share Posted July 22, 2009 Thank you I just bugging around! Link to comment https://forums.phpfreaks.com/topic/166872-solved-i-am-getting-an-undefined-variable-error/#findComment-879923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.