Brew upgrade causing libraries to be unlinked

I’m running a number of services on my local – php@7.2, postgresql, node, mariadb, etc. Every time I do brew upgrade X some of the libraries that are generally used will become unlinked (?) resulting in something like:

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib

whenever I try to run a php script.

(To solve this particular one I needed to do brew reinstall php@7.2)

My questions are:

  • why do libraries that my services are using become unlinked and how to prevent that?
  • how, looking at given error, can I determine what do I have to reinstall (in this example I was trying to run php script, so it was easy to figure out, but sometimes it’s not the case)
  • bonus question – why did running brew upgrade yarn cause brew to upgrade itself affecting my php?

This is on macOS Mojave 10.14.5