SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Montgomery, TX
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question function parameter limit

    Is there a limit on the number of parameters a function can have? I have this function that calculates a baseball slugging percentage, it has/had 5 parameters. When trying to run, I kept getting "unexpected $" on the function declaration line. When I changed it to two parameters, the error went away.

    PHP Code:
    function calculateSluggingPercentage($ab$h, $2b, $3b$hr)
      {
      
    $slg ".000";
      
    $total_bases 0;
        
      if (
    $ab 0) {
        
    $total_bases = (($h - $2b - $3b $hr) + ($2b 2) + ($3b 3) + ($hr 4));
        
    $slg number_format(($total_bases $ab), 3'.''');
        
    $slg preg_replace("/^0*/"""$slg); 
        }

      return 
    $slg;
      } 
    Thanks,

    David

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    variables can not start with a number

    -edit-
    from http://www.php.net/manual/en/language.variables.php

    Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
    -/edit-
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Montgomery, TX
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks sweatje, that hadn't crossed my mind.

  4. #4
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But still I wonder if there's limit in maximum function parameter that we can define??

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ashsys View Post
    But still I wonder if there's limit in maximum function parameter that we can define??
    Having revived a six-year old thread for your first posting, the answer to your "is there a limit" will be "yes", but the limit is likely to be several thousands (and platform dependent) because it's all related to address space in memory (particularly processor addressible stack space when parameters are being passed to a function). And even that limit could be exceeded by passing arrays of values rather than individual scalars.

    The answer to the "we can define" part of your question is "No".... and I can't think of a viable reason why you would even want to.
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint


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
  •