phpfunctionzend-frameworkarray-map

array_map cant found function in Bootstrap


I created a function in Bootstrap file and I want call it with array_map function. but it show me this error :

Warning: array_map() expects parameter 1 to be a valid callback, function 'rootCreator' not found or invalid function name in ...

This is my code that call array_map :

$controls = array('products','productsubcat','newssubcat');
array_map('rootCreator', $controls);

This is my function code:

public function rootCreator($cotroller)
{
    $frontController = Zend_Controller_Front::getInstance();
    $defaults = array('module'=>'default' ,'controller'=> $cotroller , 'action'=>'info' );
    $productRoute = new Zend_Controller_Router_Route($cotroller . '/:id/:title', $defaults);
    $router = $frontController->getRouter();
    $router->addRoute($cotroller, $productRoute);
}

Solution

  • If your function is a method of an object, you need to pass the object too.

    Try

    array_map(array($this, 'rootCreator'), $controls);
    

    If it's not on the same object, you need to pass it an instance. For static methods, you can pass the class name.