Okay I got it, so in php 8.1 the stream output cannot be empty. If it's empty or if it's a simple true false boolean it will throw an error, so what I did to get around it is quite simple:
$connection = ssh2_connection(71.45.71.163, ubu22, passw0rd, 22);
$stream = ssh2_exec($connection, 'echo "Hello world"');
if (!empty($stream)) { //if empty stop here
$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
// Enable blocking for both streams
stream_set_blocking($errorStream, true);
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
$error = stream_get_contents($errorStream);
}
Yep, and that was it. It only showed an error if $stream was empty. If it was empty it does not do any of the stream output execution. If there is no error there is no need to attempt to output any error, because if there is no error nothing is outputted anyway. If there Easy peasy.