1

I tried to do what all the person have done without problems

$customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect(array('email'), 'inner');
Mage::getSingleton('core/resource_iterator')->walk($customers->getSelect(), array(array($this, 'customerCallback')));


function customerCallback($args)
{
    $customer = Mage::getModel('customer/customer'); // get customer model
    $customer->setData($args['row']); // map data to customer model
    echo $customer->getFirstname(); // set value of firstname attribute
}

But, for me, it doesn't works an i don't know why. The error is:

PHP Fatal error:  Uncaught exception 'Exception' with message 'Warning: call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
sv3n
  • 11,657
  • 7
  • 40
  • 73
characterError
  • 55
  • 2
  • 10

1 Answers1

3

Just put this code inside a class. Example:

$test = new MyClass;
$test->run();

class MyClass
{
    public function run()
    {
        $customers = Mage::getModel('customer/customer')->getCollection()
            ->addAttributeToSelect(array('email'), 'inner');

        Mage::getSingleton('core/resource_iterator')->walk(
            $customers->getSelect(),
            array(array($this, 'customerCallback'))
        );
    }

    public function customerCallback($args)
    {
        $customer = Mage::getModel('customer/customer'); // get customer model
        $customer->setData($args['row']); // map data to customer model
        echo $customer->getFirstname(); // set value of firstname attribute
    }
}

Edit:

Please read this: http://php.net/manual/en/function.call-user-func.php

Without using a class the code has to look like this:

Mage::getSingleton('core/resource_iterator')->walk(
    $customers->getSelect(),
    array('customerCallback') // changed here
);
sv3n
  • 11,657
  • 7
  • 40
  • 73