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? Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/ 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 Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624674 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? Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624686 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 Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624687 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 Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624691 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 Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624694 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.... Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624700 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 Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624703 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; Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624718 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 Link to comment https://forums.phpfreaks.com/topic/121174-what-does-var1-var2-mean/#findComment-624722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.