Noob Q, using array_filter in class w/ class-wide variable
Posted: Wed Apr 11, 2007 11:16 am
Hi,
I have a noob question about OO in PHP.
My ultimate goal is just to use 'array_filter' function in PHP class. Please take a look at the following code:
First of all, I want to define a class-wide variable $canned_answers, but I got:
If I move the variable $canned_answers definition into function do_test, I will still get:
I guess the containsStr is not static anyway.
So, how can I use 'array_filter' function in PHP class?
thanks.
xpt
I have a noob question about OO in PHP.
My ultimate goal is just to use 'array_filter' function in PHP class. Please take a look at the following code:
Code: Select all
class testClass extends baseTestClass
{
public $canned_answers =
array(
"Case opened.",
"Update case details.",
"Case suspended.",
"Case closed.",
);
static function containsStr($value)
{
$pos = stripos($value, $this->suggested_key);
return $pos == false ? false : true;
}
public function do_test()
{
$this->suggested_key = $this->getRequestParameter('comments');
$this->suggested_answers =
array_filter($canned_answers, "testClass::containsStr"); ;
}Code: Select all
Notice: Undefined variable: canned_answers.Code: Select all
Warning: array_filter() [function.array-filter]: An error occurred while invoking the filter callbackSo, how can I use 'array_filter' function in PHP class?
thanks.
xpt