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"); Link to comment https://forums.phpfreaks.com/topic/22837-php-syntax-question/ 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. Link to comment https://forums.phpfreaks.com/topic/22837-php-syntax-question/#findComment-102915 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 Link to comment https://forums.phpfreaks.com/topic/22837-php-syntax-question/#findComment-102934 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) ;?> Link to comment https://forums.phpfreaks.com/topic/22837-php-syntax-question/#findComment-103489 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] Link to comment https://forums.phpfreaks.com/topic/22837-php-syntax-question/#findComment-103594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.