lucerias Posted October 3, 2006 Share Posted October 3, 2006 May i know what is the meaning of the following code and what is the -> sign about? Sorry for asking this kind of question, i am new to php world. I have read through some web resource but still fail to obtain the concept from the example provided. Thank you.$log->info("This page is $page"); Quote Link to comment Share on other sites More sharing options...
FrOzeN Posted October 3, 2006 Share Posted October 3, 2006 I'm not entirely sure on this, but I think -> is a pointer used to reference a function/variable to class (object).It makes sense having a read over [url=http://au.php.net/class]this[/url]. The sign *may* also be used for others things, not entirely sure as I'm quite new to php. Quote Link to comment Share on other sites More sharing options...
thedarkwinter Posted October 3, 2006 Share Posted October 3, 2006 yes that would be a class - the rest of the code would be something like:class LogClass { var $blah; // a couple if variables in the class function info($str) // a class function { echo $str; }}$page = "blah.php" // or wherever the variable for page is coming from$log = new LogClass; // assign $log as a log class$log->info("this page is $page"); // call the class functionthe [color=red]->[/color] thingy is for the properties and functions within a class, so $log->blah (without the $) would let you change the value of $blah within the class...*note: classes are very useful, have a play with them!!Cheers,Michael Quote Link to comment Share on other sites More sharing options...
lucerias Posted October 4, 2006 Author Share Posted October 4, 2006 How to echo the $blah parameter in a class? I have problem with the code below.class LogClass { var $blah; // a couple of variables in the class $blah="string"; function info($str) // a class function { echo $str; }}$page = "blah.php"; // or wherever the variable for page is coming from$log = new LogClass; // assign $log as a log class$log->info("this page is $page"); // call the class functionecho ($log->$blah) ;?> Quote Link to comment Share on other sites More sharing options...
thedarkwinter Posted October 4, 2006 Share Posted October 4, 2006 Hiwhen referring to properties of a class, you do not use the [color=blue]$[/color] sign for the variable.so it would be[code]$log->blah = "string";echo $log->blah;[/code]also, for the record if you are changing a value of a variable within a class (say in the "info" function) you use [color=blue]$this[/color][code] function info($str) // a class function { $this->blah = "string"; echo $str; }[/code] 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.