You could maybe benefit from the magical __call
method. You could say that if you need a status for a certain method, you would call a method with the same name, but with the suffix "Status". The nice thing is that you don't actually have to create all those methods with "Status" at the end, but can use a trap for it.
Additionally, you can use __FUNCTION__
to get the name of the function that is running. This is not interesting for getting the status, but might be for setting it.
Here is some example code:
class myClass {
// Use an array to keep the statusses for each of the methods you have:
private $statusses = [
"findDates" => "my original status",
"anotherMethodOfThisClass" => "another original status"
];
public function findDates($arg) {
echo "Executing " . __FUNCTION__ . ".\n";
// Set execution status information:
$this->statusses[__FUNCTION__] = "last executed with argument = $arg";
}
// ... other methods come here
// Finally: magic method to trap all undefined method calls (like a proxy):
public function __call($method, $arguments) {
// Remove the Status word at the end of the method name
$baseMethod = preg_replace("/Status$/", "", $method);
// ... and see if now we have an existing method.
if(method_exists($this, $baseMethod)) {
echo "Returning execution status for $baseMethod.\n";
// Yes, so return the execution status we have in our array:
return $this->statusses[$baseMethod];
}
}
}
// Create object
$object = new myClass();
// Execute method
$object->findDates("abc");
// Get execution status for that method. This method does not really exist, but it works
$status = $object->findDatesStatus();
echo "Status: $status\n";
The above code outputs this:
Executing findDates.
Returning execution status for findDates.
Status: last executed with argument = abc
See it run on eval.in