mtylerb Posted October 7, 2006 Share Posted October 7, 2006 I have searched around various search engines but with relatively little luck (search engines won't search for ->). I'm trying to figure out exactly what the symbols -> do. I'm just trying to fix a random quote module for Mambo. I've seen it used in phpBB but I didn't really understand it there either. So, please excuse my thick skull, the file it's used in reads:[code]<?php/*** * **/defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );$database->setQuery("SELECT * FROM mos_quotes");$quotes = $database->loadObjectList();$count = count($quotes);if (!$count){ echo ("No quotes yet entered.");}else{$id = rand(1,$count);$quote = $quotes[$id];?> <p>"<?php $quote->quote ?>" -- <?php $quote->author ?></p><p>Quote Number <?php $quote->id ?></p><?php}?>[/code]Currently though the only output I'm getting is:[quote]"" -- Quote Number [/quote]I would probably be able to figure it out and fix it relatively easy if I could understand what the -> does. I understand it has something to do with OOP but it's going right over my head. I could probably just re-write it to my own whims, but I would rather just keep the coding as close to the original as possible, not to mention my own programming would likely be less efficient then the original was intended to be. Quote Link to comment https://forums.phpfreaks.com/topic/23297-help-with/ Share on other sites More sharing options...
redbullmarky Posted October 7, 2006 Share Posted October 7, 2006 in php it can have a few uses. for the one you mention, you're right - it involves OOP. to keep it simple, take the class:[code]<?phpclass simpleclass{ function add($a, $b) { $result = $a + $b; return $result; }}?>[/code]using the -> is a way of referencing a method (function) within a class. so:[code]$test = new simpleclass();echo $test->add(5,10); // returns 15[/code]from your code, all i can see is that you maybe missing a few 'echo' statements. so:[code]<p>"<?php echo $quote->quote ?>" -- <?php echo $quote->author ?></p><p>Quote Number <?php echo $quote->id ?></p>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23297-help-with/#findComment-105649 Share on other sites More sharing options...
mtylerb Posted October 7, 2006 Author Share Posted October 7, 2006 LOL. My friend, you are a genius! I feel like a royal doofus now. How did I miss the lack of echo statements.*Sign* It was fun. Got any recommended websites to help with that OOP stuff? Quote Link to comment https://forums.phpfreaks.com/topic/23297-help-with/#findComment-105650 Share on other sites More sharing options...
redbullmarky Posted October 7, 2006 Share Posted October 7, 2006 http://www.devarticles.com/c/a/PHP/Object-Oriented-Programming-in-PHP/ is a good start to get the basics down. Further from that, the best way to learn is to get your hands dirty and look at OOP in action. I personally learnt by downloading a copy of phpBB (and other PHP packages) and looking at the code.the good thing about OOP is you can keep it as basic or make it as complex as you like. for example, the 'simpleclass' i put down a couple of posts up is a fully working class (albeit not very useful). keep it simple and move from there, as it can get messy (as i'm realising now ... :) ) Quote Link to comment https://forums.phpfreaks.com/topic/23297-help-with/#findComment-105655 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.