apeisa Posted January 20, 2011 Share Posted January 20, 2011 I am reading through source code and there is some syntax that is unfamiliar to me. First in templates there is line like these: echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>"; Why there is {} around properties? Does it have any function or does it only make code cleaner? And then at ProcessPageList.js there is lines like this: if(child.status & 1024) $li.addClass('PageListStatusHidden secondary'); What does & at that line? I have a good guess, but I have never seen that syntax before so better ask than assume This probably isn't best forum for such a general programming questions, but it would really help me to understand what is happening under the hood (and of course learn some new programming at the same time). Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2011 Share Posted January 20, 2011 Hi Apeisa, welcome to the forums, although google is your friend in this case, I'll be easy on you {} brackets Is so called Complex syntax. It allows you to use more complicated $values in parsed strings, consider following: echo "$arr['foo'][4]"; throws syntax error, unexpected T_ENCAPSED_AND_WHITESPACE echo "{$arr['foo'][4]}"; on the other hand, will work, because the curly brackets delimited parts of string, that should be considered as $variable. More here: http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex P.S.: even simple parsing can parse objects ($object->property), but I think Ryan considers it best practice to use curly brackets (not to mention it also increases readability) & operator Amp in this case is so called Bitwise And. You can read about it here: http://www.php.net/manual/en/language.operators.bitwise.php In this case, it compares two int values – page.status and value 1024. is page.status has the '1024' bit set (= if page.status value is 1 in binary form on 210th place) it continues. Link to comment Share on other sites More sharing options...
apeisa Posted January 20, 2011 Author Share Posted January 20, 2011 Thank you Adam! I tried Google (as always), but as non native English speaker I have sometimes difficulties to find right queries when it comes to special characters. Google tends to ignore single characters like { and & Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 21, 2011 Share Posted January 21, 2011 Glad to help, stick around Btw, for future reference (to better yourself at google searching ) complex syntax: http://lmgtfy.com/?q=curly+brackets+parsed+strings+php & operator: http://lmgtfy.com/?q=single+amp+operator+php in both cases, first links provide better understanding of things mentioned Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now