$obj = new Varien_Object(); $obj->setData('name', 'John'); $obj->setData('age', 25); echo $obj->getData('name').' is '.$obj->getData('age').' years old.';
class My_Object extends Varien_Object { public function _construct() { $this->_init('my_table'); // initializes table name $this->_initFields(); // initializes object fields } } $obj = new My_Object(array( 'id' => 1, 'name' => 'John', 'age' => 25 )); echo $obj->getName(); // retrieves 'John'This code example demonstrates how to create a custom object class that extends Varien_Object with additional initialization functions. The class' constructor function calls two methods to initialize the table name and object fields. Then, an instance of the modified My_Object class is created and initialized with an array of properties. Finally, the object's getName method retrieves the value of the name property. Package library: Varien_Object is a part of the Magento Core framework and is located in the Magento library directory '/lib/Varien/Object.php'.