SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have a question about a parameter

    PHP Code:

    public static function OutputRating($varItem){ //rest of the method 
    Where does the value of that parameter is coming from?
    Or
    Does this parameter get the value of the whole method?

    Or why does this parameter is put here?

  2. #2
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's coming from wherever the function is called. Somewhere in the code should be something that looks like this
    PHP Code:
    <classname>::OutputRating($variable); 
    Note that function should only be called using scope resolution operator.

    Does this parameter get the value of the whole method?
    What?

    The parameter is put there so that it is obvious what value is passed in.

  3. #3
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you mean what value is passed in into the function right?

    in this case would be $varItem sorry for my occurrences, I am learning php.

  4. #4
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes

  5. #5
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by baileylo View Post
    Somewhere in the code should be something that looks like this
    PHP Code:
    <classname>::OutputRating($variable); 
    What do you mean somewhere in the method or the whole class?

    The script I am analyzing has several method, one is OutputRating and inside that method these calls of other methods exist and all of them use the same parameter $varItem why is that posible?

    PHP Code:
    Rating::CheckRatingsByIp($varItem) == 0

     
    $averageStars Rating::CalculateAverageRating($varItem); 
    I was wondering if the $varItem where is the $varItem variable is defined? inside the braces or some where before when used in classes and methods?


    for further reference I have put the code being analyzed below

    PHP Code:
     public static function OutputRating($varItem)
          {
            
    // Verify $varItem was provided
            
    if ($varItem != null && strlen(trim($varItem)) != 0)
            {
              
    // Check if Magic QUotes is ON
              
    if (!get_magic_quotes_gpc())
              {
                
    $varItem addslashes($varItem);
              }
              
              
    // Information for the Output
              
    $averageStars Rating::CalculateAverageRating($varItem);
              
              
    // Check to see that the user has not already rated this item
              
    if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $classes      "rating" Rating::ShowStars($averageStars);
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\"><a   href=\"javascript:RateItem('{$varItem}', 1);\" title=\"1 Star\">1</a></li>\r\n";
                
    $output .= "  <li class=\"two\"><a   href=\"javascript:RateItem('{$varItem}', 2);\" title=\"2 Stars\">2</a></li>\r\n";
                
    $output .= "  <li class=\"three\"><a href=\"javascript:RateItem('{$varItem}', 3);\" title=\"3 Stars\">3</a></li>\r\n";
                
    $output .= "  <li class=\"four\"><a  href=\"javascript:RateItem('{$varItem}', 4);\" title=\"4 Stars\">4</a></li>\r\n";
                
    $output .= "  <li class=\"five\"><a  href=\"javascript:RateItem('{$varItem}', 5);\" title=\"5 Stars\">5</a></li>\r\n";
                
                
    $output .= "</ul>\r\n";
              }
              else
              {
                
    $classes      "rated " Rating::ShowStars($averageStars);
                
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\">1</li>\r\n";
                
    $output .= "  <li class=\"two\">2</li>\r\n";
                
    $output .= "  <li class=\"three\">3</li>\r\n";
                
    $output .= "  <li class=\"four\">4</li>\r\n";
                
    $output .= "  <li class=\"five\">5</li>\r\n";    
                
    $output .= " <li class=\"total\">[78]</li>";                                
                
    $output .= "</ul>\r\n";
              }
            }
            else
            {
              
    $output "";
              
    // This is a major issue. NO information can be retrieve if an item name is not passed.
              
    Error::LogError("Variable Missing""You must provide the item name for this function to find the average.");
            }
            
            return 
    $output;
          } 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •