This works:
class MyClass {
private static $data = array( 'banana', 'cherry', 'apple' );
private static function sort_by_text( $first, $second ) {
return strcasecmp( $first, $second );
}
public static function sorted_data() {
usort( self::$data, array( __CLASS__, 'sort_by_text' ) );
return self::$data;
}
}
print_r( MyClass::sorted_data() );
// Array ( [0] => apple [1] => banana [2] => cherry )
But, PHP docs always use public
callbacks.
Is the fact that callbacks can be private
just not documented well, or making them private
can lead to issues?
Callbacks are context aware and you can see that there are some bugs around it, like: https://bugs.php.net/bug.php?id=62547
https://bugs.php.net/bug.php?id=63468
But it is being fixed and therefore is supported :)
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