1

I am digging into some Magento code.

I'm looking at class Mage_Catalog_Model_Session

There is code in class Mage_Catalog_Block_Product_List_Toolbar extends Mage_Core_Block_Template function getCurrentOrder like this:

Mage::getSingleton('catalog/session')->getSortOrder();

Now, Mage::getSingleton('catalog/session') returns an object of type Mage_Catalog_Model_Session

So I would think that getSortOrder() is a method of that class, although the method seems like it would go with this toolbar class and not that session class.

This line should give me the list of methods of the class:

print_r(get_class_methods(get_class($_test)));

And it does seem to, but getSortOrder() is not listed.

So, which class is getSortOrder() a member of and how is it that it either A.) appears to be a member of a class it's not a member of, or B.) is a member of that class but does not appear in the get_class_methods() result set?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120

1 Answers1

2

Sounds like getSortOrder() is an overloaded method. See here for more info on overloading. Taken from the link:

Overloading in PHP provides means to dynamically "create" properties and methods.

get_class_methods() wouldn't display overloaded methods because they are created on the spot when called (And therefore there's no way to know about them.) A lot of frameworks use overloading for getters.

Btw, see this answer for an example of how overloading a getter would be achieved.

Community
  • 1
  • 1
Nathan Kot
  • 2,392
  • 1
  • 21
  • 31