Can I override core classes or PHP files with custom versions?
The answer is "yes" but...

Overriding an entire file means upgrades will become difficult, as you'll have to manually diff the contents of that file with the one in the new version, and reapply your changes.

If possible, try accomplishing your goal using a hook.