Derleek Posted August 25, 2008 Share Posted August 25, 2008 So i run into this code every once and a while when i'm trying to find some example code or something: $var1->$var2 Now what exactly does this represent? Quote Link to comment Share on other sites More sharing options...
Drezard Posted August 25, 2008 Share Posted August 25, 2008 Look into OOP. $var1 is a class, and $var2 is the variable within the class. So like: $class1->$var1 = 10; Daniel Quote Link to comment Share on other sites More sharing options...
Derleek Posted August 25, 2008 Author Share Posted August 25, 2008 Ok, i'm actually familiar with some OOP (i have some history with C++). So $class1->$var1 = 10; basically means; set $var1 to 10 in $class1? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 25, 2008 Share Posted August 25, 2008 yes however there are scope things you need to be observant of in OOP in the class $this->$var1 = 10 means set the instant of the class that triggered this object var value is 10 outside you use its globalscope name Quote Link to comment Share on other sites More sharing options...
Drezard Posted August 25, 2008 Share Posted August 25, 2008 That last post was confusing for me too :S sorry cooldude832. But what he was trying to say was: when declaring the variable INSIDE the class (such as): class class1 { public $var1 = 1; function test () { $this->var1 = 10; // NOT $var1 = 10; } } But in OUTSIDE use (such as): $newclass = new class1; $newclass->var1 = 10; // NOT $var1 = 10 Hope that helps Daniel Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 25, 2008 Share Posted August 25, 2008 yup way to articulate something u said you couldn't understand Quote Link to comment Share on other sites More sharing options...
Derleek Posted August 25, 2008 Author Share Posted August 25, 2008 yup that is what i meant drezard. I missed the little syntax thing "$class1->var1" not "$class1->$var1" I'll have to look into the specifics of OOP in php i guess.... Quote Link to comment Share on other sites More sharing options...
Drezard Posted August 25, 2008 Share Posted August 25, 2008 yup way to articulate something u said you couldn't understand Hehehe... Yea i know Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 25, 2008 Share Posted August 25, 2008 Or it can be a result of a mysql_fetch_object() call... $query = mysql_query("SELECT * FROM table WHERE field = '$value' LIMIT 1")or die(mysql_error()); $fetch = mysql_fetch_object($query); $someVar = $fetch->someField; Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 25, 2008 Share Posted August 25, 2008 which is an object thus you are working on an object when you do so Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.