Context
Some hooks, like admin_init, happen at a broadly predictable point in the request life-cycle. So, we can reason quite easily about what other services will be available when hooking in to this.
Others, like shutdown, are a little more unusual. It's still predictable in the sense we know that, if it takes place, then it will happen toward the end of the request ... but the thing is that a request can end early. So, it may happen after admin_init (to pick one example), or it may happen earlier.
Therefore, using this hook (and perhaps there may be other, similar hooks) increases the risk of trying to access systems that are not yet available (in the linked examples, one or more Action Scheduler classes were not yet available).
Refs:
Proposed warning
Following a discussion about this problem, we thought it may be worth introducing a non-blocking warning of some kind, to raise awareness of this danger. Perhaps:
You have added code that runs during 'shutdown'. Have you considered that this may be triggered at almost any point in the request, and have you added appropriate safe-guards to make sure any other classes or functions you are using are actually available?
Notes
Perhaps, Woo Sniffs is the wrong place for this. If so we can consider other options.
Context
Some hooks, like
admin_init, happen at a broadly predictable point in the request life-cycle. So, we can reason quite easily about what other services will be available when hooking in to this.Others, like
shutdown, are a little more unusual. It's still predictable in the sense we know that, if it takes place, then it will happen toward the end of the request ... but the thing is that a request can end early. So, it may happen afteradmin_init(to pick one example), or it may happen earlier.Therefore, using this hook (and perhaps there may be other, similar hooks) increases the risk of trying to access systems that are not yet available (in the linked examples, one or more Action Scheduler classes were not yet available).
Refs:
BatchProcessingControllera bit more robust woocommerce#48078BatchProcessingController's cleanup after a premature shutdown woocommerce#49243Proposed warning
Following a discussion about this problem, we thought it may be worth introducing a non-blocking warning of some kind, to raise awareness of this danger. Perhaps:
Notes
Perhaps, Woo Sniffs is the wrong place for this. If so we can consider other options.