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 3 of 3
  1. #1
    Regular Coder zro@rtv's Avatar
    Join Date
    Feb 2005
    Location
    on the network
    Posts
    433
    Thanks
    0
    Thanked 1 Time in 1 Post

    Internal Default Method Parameters

    quick question, sry if its stupid.

    I can't do this right?
    PHP Code:
    class Myclass{

    var 
    $bob;

     function 
    myFunc($foo $this->bob){
       echo 
    $foo;
     }


    so im doing this:
    PHP Code:
    class Myclass{

    var 
    $bob;

     function 
    myFunc($foo 'unset'){
       if (
    $foo == 'unset')
        
    $foo $this->bob;

      echo 
    $foo;
     }

    }

    Is this appropriate? or am i crazy, or stupid, or thinking about this all wrong?
    THANKS IN ADVANCE!
    ._-zro
    zro@redtv
    zro.redtv.org

    "If HTML and the Web made all the online documents look like one huge book, RDF, schema, and inference languages will make all the data in the world look like one huge database"
    -Tim Berners-Lee, Weaving the Web, 1999

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    your assumptions are correct, the more common solution is to use 'null' (no quotes...see below) as the default, rather than strings that could be confusing.
    e.g.
    PHP Code:
    function myFunc($foo=null) {
      if(
    $foo==null) {
        
    $foo=$this->bob
      


  • #3
    Regular Coder zro@rtv's Avatar
    Join Date
    Feb 2005
    Location
    on the network
    Posts
    433
    Thanks
    0
    Thanked 1 Time in 1 Post
    o yes, of course!
    duh. what was i thinking?

    Thanks so much fr the kick in the pants.
    I swear sometimes i just stare at this shtuff 2 long and i lose my mind a bit.

    thanks again!
    ._-zro
    zro@redtv
    zro.redtv.org

    "If HTML and the Web made all the online documents look like one huge book, RDF, schema, and inference languages will make all the data in the world look like one huge database"
    -Tim Berners-Lee, Weaving the Web, 1999


  •  

    Posting Permissions

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