I don't think this is correct. From the VI auto-setting man page (:help auto-setting)...

Note that for the first form all of the rest of the line is used, thus a line
like:
/* vi:ts=4: */ ~
will give an error message for the trailing "*/". This line is OK:
/* vi:set ts=4: */ ~

If an error is detected the rest of the line is skipped.

I think that is why your code may not have worked...