Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Undefined Variables

    I took this code, below, from http://www.oxyscripts.com/viewcode.php?id=22. This is just a few lines
    PHP Code:
    <?php
    function sdie($desc)
     {
     echo 
    $desc;
     exit;
     }
    Variables $desc. Where is it defined? This may be a beginner question, but as I have been moving into more advanced scripting as my knowledge empowers me, I see more of 'undefined' variables. Could someone tell me if I am wrong, or explain them to me?

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $desc is a parameter to the function. It gets defined the moment you call the sdie() function, like sdie('hello world'). That's why your sample code hasn't got any undefined variables, everything is normal and ok here.
    De gustibus non est disputandum.

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    function sdie($desc)
    {
    echo $desc;
    exit;
    }

    $desc is defined where shown above

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mordred got there first with a much better explanation

  • #5
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Mordred,

    so when the code goes
    PHP Code:
    echo $desc
    what does it echo?

    Thanks for the help
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:

    <?php

    function sdie($desc)
     {
     echo 
    $desc;
     exit;
     }

    sdie('Hello World!'); // prints Hello World!

    sdie('!dlroW olleH'); // prints !dlroW olleH

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?php
    function sdie($desc)
    {
      echo 
    $desc;
      exit;
    }

    sdie('Oooger Booger');

    ?>
    Heh, beaten by a few mins

  • #8
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sweet, I see know! Thanks guys!
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!


  •  

    Posting Permissions

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