Your code tests fine for me.
I ran
$tw = new TwitchApi('ValidClientID', 'ValidSecret', 'RedirectForThisClient');
$r = $tw->get_tokens('A Code');
print_r($r);
And was returned
{"access_token":"REDACTED","refresh_token":"REDACTED","token_type":"bearer"}
Note: no expires_in as it was a legacy clientID tested with
Under PHP 7.2.24 on the machine tested on