array_map не работает в классах

Я пытаюсь создать класс для обработки массивов, но не могу заставить array_map () работать с ним.

<?php
//Create the test array
$array = array(1,2,3,4,5,6,7,8,9,10);
//create the test class
class test {
//variable to save array inside class
public $classarray;

//function to call array_map function with the given array
public function adding($data) {
    $this->classarray = array_map($this->dash(), $data);
}

// dash function to add a - to both sides of the number of the input array
public function dash($item) {
    $item2 = '-' . $item . '-';
    return $item2;
}

}
// dumps start array
var_dump($array);
//adds line
echo '<br />';
//creates class object
$test = new test();
//classes function adding
$test->adding($array);
// should output the array with values -1-,-2-,-3-,-4-... 
var_dump($test->classarray);

Это выводит

массив (10) {[0] => int (1) [1] => int (2) [2] => int (3) [3] => int (4) [ 4] => int (5) [5] => int (6) [6] => int (7) [7] => int (8) [8] => int (9) [9] => int (10)}

Предупреждение: отсутствует аргумент 1 для test :: dash (), вызываемого в D: \ xampp \ htdocs \ trainingdvd \ arraytesting.php в строке 11 и определенного в D: \ xampp \ htdocs \ trainingdvd \ arraytesting .php в строке 15

Предупреждение: array_map () ожидает, что параметр 1 будет допустимым обратным вызовом, функция '-' не найдена или недопустимое имя функции в D: \ xampp \ htdocs \ trainingdvd \ arraytesting.php в строке 11 NULL

Что я делаю не так или эта функция просто не работает внутри классов?

43
задан RavatSinh Sisodiya 30 November 2013 в 04:39
поделиться