protected function detectPhpBinaryPathAndFilename()
    {
        if (defined('PHP_BINARY') && PHP_BINARY !== '' && dirname(PHP_BINARY) === PHP_BINDIR) {
            if ($this->checkPhpBinary(PHP_BINARY) === null) {
                return [PHP_BINARY, null];
            }
        }

        $environmentPaths = explode(PATH_SEPARATOR, getenv('PATH'));
        $environmentPaths[] = PHP_BINDIR;
        $lastCheckMessage = null;
        foreach ($environmentPaths as $path) {
            $path = rtrim(str_replace('\\', '/', $path), '/');
            if (strlen($path) === 0) {
                continue;
            }
            $phpBinaryPathAndFilename = $path . '/php' . (DIRECTORY_SEPARATOR !== '/' ? '.exe' : '');
            $lastCheckMessage = $this->checkPhpBinary($phpBinaryPathAndFilename);
            if (!$lastCheckMessage instanceof Error) {
                return [$phpBinaryPathAndFilename, $lastCheckMessage];
            }
        }

        return [null, $lastCheckMessage];
    }