I have a "static class" used as a singleton (because there's never a need to have multiple instances), and other classes that extend it and are used in the same way.
At some point in the processing, the extended class will call parent::doThis(), with doThis ultimately doing a usort.
The callback of the usort should be in the calling class, as each will handle sorting differently. Can something like "class::method()" be the string for a usort callback, and if so, is there a way for the parent class to know which class called it without me passing that as an argument, so that it can name the calling class's callback for the usort?
class parentClass {
protected static function doThis($data) {
// do stuff, then
usort($data, "myCallingClass::cmp()"
}
}
based on some means of the parent determining what myCallingClass is, or does it need to be
class parentClass {
protected static function doThis($data, $calling_class) {
// do stuff, then
usort($data, $calling_class . "::cmp()"
}
}
I think you should be able to do this with Late Static Bindings:
usort($data, function($a, $b) {return(static::cmp($a, $b));});