Error when using array_filter with static functions in class
i have a class
like this
开发者_StackOverflow社区class im_a_class
{
static function not_empty() {...}
function render() { return array_filter($array,'self::not_empty') };
}
this code works in php 5.3.0 but doesn't work in version 5.2.8.
i had to put it out and use it like this
function not_empty() {...}
class im_a_class
{
function render() { return array_filter($array,'not_empty'); }
}
this way it works but...
i want to know what options do i have.
please help thanks.
You can do it like this:
return array_filter($array, array(__CLASS__, 'not_empty'));
I'm surprised 5.3.0 allows this. self::
means nothing to array_filter
, as array_filter
is not part of your class.
You should be accessing the function using im_a_class::not_empty
(which is the function's fully-qualified name)
精彩评论