Adding this to 3.X as needed for Matomo for WordPress.
The removed code should actually not be needed as we added a while ago
session_status() to correctly check if a session is already active or not. SID constant is not reliable.
In this case problem was this https://3v4l.org/bpUFK
Basically a session was started by some other plugin causing the SID constant to be set. The plugin also directly closed the session again so we still attempted to start the session (which is correct). But then Zend falsely assumes session is started because of the SID constant when there is actually no session.
SID is not reliable for this purpose and be better to rely on
session_status() which we added a while back