// Create a new Varien_Object instance $obj = new Varien_Object(); // Set a value of the method 'myMethod' $obj->setData('myMethod', 'Hello, World!'); // Retrieve the value of the method 'myMethod' $value = $obj->getMethod('myMethod'); echo $value; // Output: Hello, World!
// Create a new Varien_Object instance $obj = new Varien_Object(); // Set a value for the method 'myMethod' $obj->setData('myMethod', function($arg1, $arg2) { return $arg1 + $arg2; }); // Call the method 'myMethod' $result = call_user_func_array([$obj->getMethod('myMethod'), 'bindTo'], [$obj, 1, 2]); echo $result; // Output: 3In this example, we set a closure as the value for the method 'myMethod' using the setData() method. We then call the method using the call_user_func_array() function, passing in the closure as the first argument, and binding it to the current object using the 'bindTo' method. The closure takes two arguments, which are added together and returned. The output will be 3. Package library: Magento Framework