noobie here - where can I find good defs for =>, ->, {} ?

Discussion in 'PHP' started by Johnny_G, Nov 4, 2008.

  1. #1
    I have recently started working with PHP by getting into PHPBB3. The logic isn't too bad going thru the code (I am familiar with C and VB) but I cannot find any definitions for items like =>, ->, {SOME_TEXT}. They are used often, by the placement and context the appear to have some good uses, I just can't find any references on how. I'm dissapointed to find that search engines cannot find => or -> on sites. Any help would be fantastic!

    Thanks, John
     
    Johnny_G, Nov 4, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    shallowink, Nov 4, 2008 IP
  3. Johnny_G

    Johnny_G Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks shallowlink, thats a great start!
     
    Johnny_G, Nov 4, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    The curly brackets {} can be used at:

    function / class
    function name() {
    
    }
    
    PHP:
    if-else statement
    if (what) {
    
    } else {
    
    // !what
    
    }
    
    PHP:
    loop
    for () {
    
    }
    
    foreach () {
    
    }
    
    while () {
    
    }
    
    PHP:
     
    ads2help, Nov 4, 2008 IP
  5. Johnny_G

    Johnny_G Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The examples below show where my interest in the curly brackets is coming from, trying to figure this out.

    This if from an index.php file:
    // Assign index specific vars
    $template->assign_vars(array(
    	'TOTAL_POSTS'	=> sprintf($user->lang[$l_total_post_s], $total_posts),
    	'TOTAL_TOPICS'	=> sprintf($user->lang[$l_total_topic_s], $total_topics),
    	'TOTAL_USERS'	=> sprintf($user->lang[$l_total_user_s], $total_users),
    	'NEWEST_USER'	=> sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),
    
    .... similar code ....
    
    $template->set_filenames(array(
    	'body' => 'index_body.html')
    );
    Code (markup):
    This is from the "index_body.html" file, referenced in "index.php" above
    <!-- IF NEWEST_USER -->
    	<h3>{L_STATISTICS}</h3>
    	<p>{TOTAL_POSTS} &bull; {TOTAL_TOPICS} &bull; {TOTAL_USERS} &bull; {NEWEST_USER}</p>
    <!-- ENDIF -->
    
    <!-- INCLUDE overall_footer.html -->
    Code (markup):
    I'm looking for a definition of how things like {TOTAL_POSTS} is linked to 'TOTAL_POSTS'.
     
    Johnny_G, Nov 5, 2008 IP
  6. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #6
    Here's all I could find to explain it. The nutshell is, they are assigned by the Template Object. Unfortunately it doesn't really explain how its done, just outlines what you have already noted. I'm making an assumption that the template engine is essentially looking for the {} and uses it to lookup the correct values.

    http://wiki.phpbb.com/Template.assign_vars
    This is the user friendly version of the above :
    http://www.phpbb.com/kb/article/phpbb2-template-tutorial/

    Here's a list of phpbb2 template variables (might be out of date but still useful).
    http://www.jakob-persson.com/node/541
     
    shallowink, Nov 5, 2008 IP
  7. Johnny_G

    Johnny_G Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That is helpful, thanks!
     
    Johnny_G, Nov 5, 2008 IP
  8. sarahk

    sarahk iTamer Staff

    Messages:
    28,932
    Likes Received:
    4,563
    Best Answers:
    124
    Trophy Points:
    665
    #8
    Not directly in with your question, but you'll be asking it soon enough :)
    
    // lets get some variables to play with
    $a = 'hello world';
    $b = "hello world"; // same as $a but uses double quotes so PHP looks to see if there are any embedded variables in the string
    $c = "my test phrase is: $b";
    $d = "my test phrase is: {$b}"; //explicitly tells PHP were the variable starts and stops
    
    $myArray = array('apple','pear','orange');
    $e = "I would like an $myArray[0] please"; //won't work because PHP doesn't understand what to do with the array
    $f = "I would like an {$myArray[0]} please"; //will work because the {} tell PHP how to handle the variable
    
    PHP:
     
    sarahk, Nov 5, 2008 IP