SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,529
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Syntax issue with Function Parameters

    What is wrong with the syntax of this Function...
    PHP Code:
        function generateSurveyItem($dbc$questionNo$articleSurveyQuestionID$surveyResponse=NULL$errors[$articleSurveyQuestionID]){
        } 

    Apparently NetBeans didn't like it when I added the last parameter: $errors[$articleSurveyQuestionID]...


    When I aaded to my call to the Function in another script, NetBeans seemed to be okay with this...
    PHP Code:
        $surveyItemArray[$articleSurveyQuestionID] = generateSurveyItem($dbc$questionNo$articleSurveyQuestionID$surveyResponse$errors[$articleSurveyQuestionID]); 
    Thanks,


    Debbie

  2. #2
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Netbeans is just an IDE so it may complain about something even though the syntax is perfectly legal php syntax (which does not look correct in this case)
    So try to run your function. Do you get any php errors?
    The function signature should be like this:

    function generateSurveyItem($dbc, $questionNo, $articleSurveyQuestionID, $surveyResponse=NULL, $myParam){
    }

    You can them call this function the way you do now and the $errors[$articleSurveyQuestionID] that you pass to function will become the value of $myParam inside your function.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    77
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're not allowed to create an argument for a function in the form of an array key like above (which will result in a parse error). Just call the last argument as $errors, and then pass the $errors[$articleSurveyQuestionID] variable as a parameter to it:

    PHP Code:
    function generateSurveyItem($dbc$questionNo$articleSurveyQuestionID$surveyResponse=NULL$errors){ 


  4. #4
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,529
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by modernW View Post
    You're not allowed to create an argument for a function in the form of an array key like above (which will result in a parse error). Just call the last argument as $errors, and then pass the $errors[$articleSurveyQuestionID] variable as a parameter to it:

    PHP Code:
    function generateSurveyItem($dbc$questionNo$articleSurveyQuestionID$surveyResponse=NULL$errors){ 

    Okay, thanks for the tip. (I would have never guessed that one!)

    As it turns out, I may be able to just use a single variable there.

    (Am stuck in the MOST COMPLICATED script I have ever written and drowning in several areas...)

    Thanks,


    Debbie


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
  •