if want to do this following:
$filteredValues = array_filter($rawValues, function($rawValue) {
return $this->validateValue($rawValue);
});
validateValue is a private method in the same class.
How can i use $this context in array_filter in this way?
If you use PHP 5.3, PHP does not recognize $this as closure, you need to do a trick like JavaScript:
$self = $this;
$filteredValues = array_filter($rawValues, function($rawValue) use ($self) {
return $self->validateValue($rawValue);
});
Note that the above will only give you access to the object through the public API of the object. This is different from the 5.4 support for Closure rebinding which allows full access to $this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With