ID:               15694
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: linux
 PHP Version:      4.1.1
 New Comment:

>From the manual (http://www.php.net/array_filter):

  Note: Instead of a function name, an array containing an   
  object reference and a method name can also be supplied.

So the correct code would be:

<?php
error_reporting(E_ALL);

class test {
    function filter($var) {
        return preg_match('/test/', $var);
    }
}

$test = new test;

$array["test"] = "This is a test";
$array["not"] = "This shouldn't be here";
$array = array_filter($array, array('test', 'filter'));
print_r($array);

?>


Torben



Previous Comments:
------------------------------------------------------------------------

[2002-02-23 19:56:56] [EMAIL PROTECTED]

There is no way to safely use array filter from within a class.  Using
class::functionname should work for the callback function as in:
<?php
class test {
  function filter($var) {
    return preg_match('/test/',$var);
  }
}
$array["test"]="This is a test";
$array["not"]="This shouldn't be here";
$array = array_filter($array, "test::filter");
print_r($array);
?>

but this just says:
Warning: array_filter() expects argument 2, 'test::filter', to be a
valid callback in /usr/home/ribrdb/web/php/classtest.php on line 11



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=15694&edit=1

Reply via email to