If you are looking at the .phtml file, first thing to do is realize that every .phtml file is working in the context of some instance of some Block class. So first find out what block class you're in, either by looking at the comments, or printing/echoing/var_dumping/etc the value returned by get_class($this)
.
Then you could grep the app/code directory for the class declaration of the block, i.e grep -irn 'class Mage_Catalog_Block_Product_List_Toolbar' app/code/core
Note that, whether or not you're on *nix, if you're using an IDE, you can probably just tell your IDE to teleport you to the class file/declaration by standing on PHP doc comments such as those found in the core's .phtml files, i.e. @see Mage_Catalog_Block_Product_List_Toolbar
and pressing whatever shortcut triggers that function on your IDE.
BTW, a note about getter methods:
Pretty much all Magento classes inherit from the Varien_Object class, which implements __call() -- which, if you recall, is triggered when invoking inaccessible methods on an object -- so that when you call, say, $this->getBananas()
on an object, Magento won't throw a fatal error, but instead will check if the internal $data
array of the object contains a key "bananas", and return its value, or NULL if it doesn't exist.
The implications of this is that sometimes you'll see a call like $this->getSomething()
and then you'll grep the code looking for function getSomething()
, but you won't find it, because it's not declared anywhere, it's just the template making use of the magic getter behavior of Varien_Object.
Still, grepping the Magento source is super useful. Plus, if you grep a getter function and you don't find its declaration, then you know that the code is just accessing a data attribute, which is perfectly helpful information as well.