SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Iasi, Romania
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parse error defining a custom function

    Hi!
    I tried to define a custom function like

    PHP Code:
    function myfunction($_SESSION['userid']){
    //function code goes here

    but I receive a parse error:
    Parse error: parse error, expecting `')'' in /home/www/mysite/functionpage.php on line 10 (line 10 being the line on which the function is defined)
    Note: variable userid is already stored in $_SESSION and session_start() is executed before defining function,to resume session.
    Last edited by zico; Jul 26, 2002 at 04:52.

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When defining a function, the variable you use in the function is relative only to the function. When you CALL the function, thatt's when you would use the session variable.
    PHP Code:
    function myfunction($someonesid){

    //function code goes here

    }

    $result myfunction($_SESSION['userid']); 
    sketch
    Aaron Brazell
    Technosailor



  3. #3
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    indipendent from what your scope is,
    you could:

    a)
    PHP Code:
    function myfunction()
    {
    // inside this function
    // you can use $_SESSION['userid'] directly
    // this is one of the advantages of
    // the superglobal arrays

    b)
    PHP Code:
    function myfunction($id){
    //function code goes here
    }

    myfunction($_SESSION['userid']); 
    )b is better

    pippo
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


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
  •