ilyakar Posted December 9, 2010 Share Posted December 9, 2010 sorry for nooby question, but what does this "->" mean in php? Link to comment Share on other sites More sharing options...
jeffman Posted December 9, 2010 Share Posted December 9, 2010 It creates a "path" to an object element. Read more about objects here: http://www.php.net/manual/en/language.oop5.basic.php Link to comment Share on other sites More sharing options...
Fmdpa Posted December 9, 2010 Share Posted December 9, 2010 Other languages including JavaScript, Ruby, and Java use the period (.) instead. Link to comment Share on other sites More sharing options...
Fritz_Doll Posted December 10, 2010 Share Posted December 10, 2010 C uses it for paths when playing with pointers. think of it as an arrow pointing you to another location. Link to comment Share on other sites More sharing options...
jeffman Posted December 10, 2010 Share Posted December 10, 2010 Close. :)In C, the datatypes called struct and union are a lot like objects. Member are normally accessed with dot notation, the way JavaScript does it. So a typical assignment could look like this:my_struct.my_element = 5;Because C is "closer to the metal" than PHP or JavaScript, it also lets you designate variables as pointers: a number that represents a memory address. You can create a pointer like this:my_struct_pointer = &my_struct;The & is the address operator. Prefixed to my_struct, it says "return the memory location of my_struct."To access my_element from my_struct_pointer, we have to use -> instead of the dot:my_struct_pointer->my_element = 5;For anyone who's followed this far and did not know already, you can see how the dot, & and -> symbols have inherited their meanings in JS and PHP from their common ancestor.I'm not sure why PHP chose the dot for the concatenation operator (anyone?) but it's not as weird as it might seem. C itself has no concatenation operator. Strictly speaking, it doesn't even have strings. What we call a string is an array of characters in C, and you need a function (or at least a routine) to concatenate character arrays. Funky, huh?But maybe now it makes sense why, if you have a string like this:s = "hello";s[1] returns "e" Link to comment Share on other sites More sharing options...
Fmdpa Posted December 10, 2010 Share Posted December 10, 2010 Yeah, the + operator is much more logical for concatenation. Speaking of C, I downloaded the PHP source code today just to see how they mathematically can find the square root of a number. (I've never figured out how they do it without having tables of squares/square roots) And guess what? I found out that the PHP sqrt() function is just based on the C sqrt function. What a letdown! I was hoping to find some algorithm. I guess I'll just do a search on the internet for it. I actually like the -> better than a period. It is more self explanatory, even if it is more to type. Link to comment Share on other sites More sharing options...
ilyakar Posted December 10, 2010 Author Share Posted December 10, 2010 thanks for all your replies you guys, helped me out alot Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.