Development environment
- PHP version: 7.3
- Laravel version: ^6.2
- State machine version: ^2.0
Hello, I'll try to use the state machine in one of my projects. I have installed and set up the state machine according to the documentation. but when I run the callbacks using the state machine getting an error.
PHP Deprecated: call_user_func_array() expects parameter 1 to be a valid callback, non-static method App/Services/ConsultationSession::afterPatientCancel() should not be called statically in /Volumes/My Files/web-root/sites/sample-projects/laravel-6/vendor/winzou/state-machine/src/SM/Callback/Callback.php on line 75
This is my state machine config file.
return [
'consultation' => [
'class' => 'App\User',
'graph' => 'consultation',
'property_path' => 'state',
'states' => [
'pending', 'timeout', 'cancelled', 'doctor_confirmed'
],
'transitions' => [
'timeout' => [
'from' => ['pending'],
'to' => 'timeout'
],
'cancel' => [
'from' => ['pending'],
'to' => 'cancelled'
],
],
'callbacks' => [
'after' => [
'after_cancel' => [
'on' => 'cancel',
'do' => ['App\Services\ConsultationSession', 'afterPatientCancel'],
'args' => ['object']
],
],
]
],
];
And if I change the callback function to static or call the function using an object (new App\Services\ConsultationSession()), the error is solved.
if I use call back using an object (new App\Services\ConsultationSession()), I can't cache the configs.
Error::("Call to undefined method App\Services\ConsultationSession::__set_state()")
So what's the issue and how can I solve it? Thanks.