Learning only what you think you need helps you solve that problem. It doesn't help you understand the limitations of your knowledge or decide what problems are worth working on.
My experience is that people who only learn by doing tend to have very shallow knowledge that hits a wall sooner rather than later.
Ideally you start your PhD when you already have very good foundational knowledge from a Bachelor's and a Master's program, found it a rewarding experience, achieved outstanding academic outcomes and now want to dive even deeper and make (more) contributions. In the US it's often directly PhD after Bachelor, but then there's some coursework still so you can aquire more of the fundamentals.