Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call a static method in a custom magento class

I have a custom model in a custom Magento model with a static function:

class ABC_Module_Model_ClassName
{
    static public function send ( $something)
    {
         // do something static
    }
}

Now I call the function like this:

ABC_Module_Model_ClassName::send($something); // works and is nothing wrong with it

More for consistency purposes, I would like to know if Mage has an internal way of calling static methods, something like this:

Mage::getModel('abc/module_className')::send($something); // this is wrong
// or 
Mage::getModel('abc/module_className', send($something)); // with a callback or something
like image 703
Elzo Valugi Avatar asked Jan 29 '26 17:01

Elzo Valugi


1 Answers

Given that any method like Mage::getModel() will actually return an instance of the class, you'll be calling it dynamically rather than statically. E.g you'd be doing $module->staticMethod(); instead of Module::staticMethod()..

So your best best is to

  • either put the static method as a regular function so it'll be available globally,
  • put all your static methods in one class and name the class something like Common so you won't have to type the really long name,
  • or just call it statically the way you've done in your question e.g Module::method().

In the end, the only way to call a method statically is via Class::method().

like image 108
Ali Avatar answered Feb 01 '26 06:02

Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!