1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Double Dollar Sign

Discussion in 'PHP' started by T0PS3O, Feb 9, 2005.

Thread Status:
Not open for further replies.
  1. #1
    Keep seeing weird stuff in the OsCommerce code...

    What is a double dollar sign variable? A G search doesn't show any relevant results whatsoever and before I go fix these 'typo's' I need to know whether they are just typo's or not.

    Example:

    <?php
      if (isset($$payment->form_action_url)) {
        $form_action_url = $$payment->form_action_url; //see the $$ ?!  :confused: 
      } else {
        $form_action_url = tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');
      }
    
      echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');
    
      if (is_array($payment_modules->modules)) {
        echo $payment_modules->process_button();
      }
    
      echo tep_image_submit('button_confirm_order.gif', IMAGE_BUTTON_CONFIRM_ORDER) . '</form>' . "\n";
    ?>
    PHP:
    I need to get into this OO stuff and advanced 'beyond the Bible' coding.

    -> and => is all new to me as well. Any one know a good intro to this type of coding?
     
    T0PS3O, Feb 9, 2005 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    digitalpoint, Feb 9, 2005 IP
  3. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #3
    php.net has all the best information. Read the comments as well as the documentation.
     
    nevetS, Feb 9, 2005 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Without a doubt php.net has to be the #1 php resource but...

    if you try looking up $$ without knowing that they are called variable variables and you're stuffed. The same with things like when do you pass a variable with &$myvar versus receiving it with &$myvar versus a straight parameter pass.

    Back to the post...

    Basically what's happening is that a variable is being created with the same name as the variable's value.

    therefore
    $a = 'dog';
    $$a = 'woof';
    echo $dog;
    Code (markup):
    will output 'woof'

    This is useful but not an everyday tool for joe average coders, that said, I've used it this week and it make my life much easier.

    Sarah
     
    sarahk, Feb 10, 2005 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sarah, exactly what my problem was.

    I'm on php.net all day every day just for reference. I'd consider myself a medium to advanced PHP nerd, well... at least 3 years ago. Now I picked up on it again it seems to have moved on a LOT!

    I searched on Google for all obvious combo's like 'double dollar sign variable php' etc. Google doesn't really like searches with characters like $ so that didn't get me far either.

    The PHP Bible and another few books got me where I am now but it seems I could do with a next millennium programming style PHP book. If anyone can recommend a good one that covers stuff like the variable variables and -> and => etc. I'd be glad to hear about it.

    Have to do some serious OsCommerce hacking so would be handy to get up to spec so I'll be able to contribute standardized re-usable code as well.
     
    T0PS3O, Feb 10, 2005 IP
  6. Juls

    Juls Well-Known Member

    Messages:
    1,867
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    170
    #6
    heh nice... variable variable.... never have had to use it yet myself but you never know... :).... what kind of module are you making for oscommerce? i have been modifying & hacking oscommerce for 2 years now and zen cart since its release. the hardest part for me is going from structural to object oriented programming... i still have some problem with it other than the easy stuff...

    on my things to do list:
    -code an application base
    -get working on my librairy of php classes

    good luck...
     
    Juls, Feb 11, 2005 IP
  7. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I just released my first contribution (ePDQ Barclays UK Payment Module) and this rewarding feeling I have must be what Opens Source is all about. Even when I realize it's ugly code (mainly because of previous code already there). I didn;t have the time to make it as good as I would have wanted bu people were desparate so I sort of prematurely released it nonetheless.

    The OO stuff is still bugging me too. I'm getting the hang of reading it now but writing it is a different story. Things like Variable Variables might be handy but certainly don't make it easier to read.

    I've written 10K+ lines of PHP before but all old school 'structural' if that's what you call it.

    I have to say, turning OsC is such a relief when you've been bound to limited 3d party stuff. Loads and tonnes and piles of stuff I still ahve in the back of my mind, ready to start coding on to make it even better.
     
    T0PS3O, Feb 11, 2005 IP
  8. neterslandreau

    neterslandreau Peon

    Messages:
    279
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Variable variables are great for assigning key=value in an associative array. i.e.:
    
    for(reset($_POST); $key = key($_POST); next($_POST)) {
      $$key = $_POST[$key];
    }
    
    Code (markup):
     
    neterslandreau, Feb 11, 2005 IP
    david_sakh likes this.
  9. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #9
    Wow... it is as if you were speaking Chinese to me... I really need to learn PHP :(

    BUt, believe it or not, there aren't any schools to learn that here! All you can get are some crappy lessons of very basic html, and after that they give you a diploma with "webmaster" on it :D
     
    fryman, Feb 11, 2005 IP
  10. neterslandreau

    neterslandreau Peon

    Messages:
    279
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #10
    There wasn't any such thing as HTML when I was going to school. Aa a matter of fact, even BASIC was still just a gleam in Bill Gates' eye when I graduated from H.S.
     
    neterslandreau, Feb 11, 2005 IP
  11. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #11
    He he... I remember learning basic when I was a kid...

    I am now reading a book about PHP. Of course, it takes me half an hour to understand one page... and I still have another 880 to go
     
    fryman, Feb 11, 2005 IP
  12. neterslandreau

    neterslandreau Peon

    Messages:
    279
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I think just about everybody "cut their teeth" with BASIC..

    As far as learning PHP, I think your best bet would be to practice the code as you read the book. If you're anything like me, reading techie stuff puts me right to sleep. Plus, I never really get what is being said until I use it and play with it.

    And not to overwhelm you, but if you're using PHP to create websites, look into Smarty Templates. They will help you to develop good programming practices, i.e. keeping your PHP functions seperate from your HTML.
     
    neterslandreau, Feb 11, 2005 IP
  13. NitinGupta

    NitinGupta Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    i.e. evaluate from left to right
    there is no operator called $$ in php

    simple way is rewrite $$$var to ${${$var}} and you will be able to understand better.

    you can have $$$var or $$$$$var etc...

    as long as evaluation of each $ from left to right results in a defined variable.

    So there is no reference etc, its just a plain left to right token evaluation in php grammar.

    Some guy had asked my friend the same question in interview and then explained him that it is reference to reference, which is completely wrong. It has nothing to do with reference.
    It's simple php grammar:
    evaluate anything after $ (with in same side of another operator) and treat $(evaluated value) as variable, and look up the symbol table.

    for e.g.
    $var1 = 'dog';
    $$$var1 = 'bark';
    would give you:
    PHP Notice: Undefined variable: dog
    (i.e. it didn't find $dog)
    $$$var is evaluated as ${${$var1}} and in each step php will try to find the variable in symbol table or will create one if there is an assignment operation immediately.

    another example is:

    ${'hello' . 'world'} = 'monkeyman';
    echo $helloworld

    other example is this:
    $var1 = 'dog cat';
    $$var1 = 'bark';
    echo $dog; //undefined
    echo ${'dog cat'}; //prints bark
     
    NitinGupta, Apr 13, 2010 IP
Thread Status:
Not open for further replies.