如何根据不同的条件扩展不同的类

The code is below:

$extend_class = 'PHPUnit_Framework_TestCase';
version_compare(PHP_VERSION,5.6,'>=') && $extend_class = 'TestCase';
use PHPUnit\Framework\TestCase;
class unitTest extends $extend_class{}

It does not work and how to make it works?

I can see where you're coming from with this one. One alternative pattern that you could follow is to set an $isUnitTesting boolean to give yourself the different behaviours. I imagine it's in relation to connecting to a database?

First of all you have to define the variable of the class name you want to extend from then after compare the version is true change the variable letting it include the class name crosponding to that php version after that extend from the class name in the variable

 $extend_class = 'PHPUnit_Framework_TestCase';
    If(version_compare(PHP_VERSION,5.6,'>=')  ==true){$extend_class = 'TestCase';}
    use PHPUnit\Framework\TestCase;
    class unitTest extends $extend_class{}