I don’t know about PHP, but both Python and Ruby have module/import semantics that explicitly allow functions to be smuggled across “visibility”/access boundaries. So they can’t really do this sort of optimization, at least not without breaking a whole bunch of real code.
Python and Ruby are aren't going to benefit (much) from the former and the latter doesn't apply, which is probably why it hasn't been a priority in either language.
GWT was doing tree shaking for Java to JavaScript compilation before most JavaScript programmers had the tool chain for it.
[1] https://groups.google.com/g/comp.lang.lisp/c/pspFr1XByZk
https://ml.cddddr.org/scheme/msg00189.html
Lucid Common Lisp had a tree shaker as part of their delivery tool. That one was developed from 1988 onwards.