You never know if you will finish your PhD. In fact, 50% drop out. Imagine spending 4 years of your life and then quitting with little to show for it.
First of all, PhD is too long (in the US). You spend 1 - 1.5 years taking grad classes that have little relevance to your subfield. If you haven't done research in undergrad, you spend the first year figuring out what is research. IF you did, there's still a lot less hand-holding as a PhD researcher compared to an undergrad researcher.
Now let's talk about research. First, you need to come up with a good idea that no one thought of it before. This requires understanding of all the previous research.
Then you try to implement the idea. Even if you implemented everything correctly, if your method is not better than the state of the art, you just wasted your time. (Of course, you need to implement the state of the art also)
Do you want to become a professor? Forget about. There are so many bright PhDs competing for a few academic openings. Even if you become a professor, it will take 10 years and a lot of work to get tenure. And if you finally become a professor, the pay is terrible compared to the industry.
I'm not even talking about PhD in other subfields like Physics, where people become Google's SWE after finishing their PhD. Such a waste.