Bug #15694 Updated: array_filter does not work withing classes
| From: | torben@php.net | Date: | Sun, 24 Feb 2002 01:07:28 +0000 |
| Subject: | Bug #15694 Updated: array_filter does not work withing classes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-879@lists.php.net to get a copy of this message | ||
ID: 15694
Updated by: torben@php.net
Reported By: ribrdb@yahoo.com
-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] ribrdb@yahoo.com
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