How to set default post editor based on role?

create_function() is deprecated as of PHP 7.2.0, so you should avoid using it. Instead, use an anonymous function.

Additionally, it’s better the check the current user role inside the callback function, so that the current user role is checked when the filter is applied, not when the hook is added, which could be before the current user role can be determined.

add_filter(
    'wp_default_editor',
    function( $default_editor ) {
        if ( current_user_can( 'editor' ) || current_user_can( 'author' ) ) {
            $default_editor="html";
        }

        return $default_editor;
    }
);