Yes it can be another solution but if you need just a value (or an array of values) to be avail in view/template or other parts of code it seem to me that this add a bit of overhead.
In my opinion the stackoverflow method is good when you need to do some more complex operation and you need it to be executed without adding code here and there.
Consider also that if the parameter is not constant and change during user operation, in the end you will store/retrive it in session through the class.
For passing value, I would still go directly for session storage, I’m for the KISS approach.