Academia as a career, unless you're unambiguously one of the top minds of your generation, is a bad idea. That boat has sailed and sunk.
However, a PhD in math or CS will make you eligible for higher-quality jobs more quickly than a Master's degree. There's a certain prestige that PhDs have that someone like me probably won't, and by the time you're 35+, it's almost impossible to go back, due to a combination of financial problems and admissions (you're now what is called "non-traditional").
I left a math PhD program for an internship on Wall Street. It was the right decision for me, especially because it got me on the job market before the Crash of 2008. Would I recommend that for everyone? No, I wouldn't.
By the time you are 40, whether you have a working brain or not will be a function of the quality of work you did in your 20s and 30s. If you do a decade or more of stupid work-- and the work most people get assigned is that-- you'll have lost your edge. On the other hand, if you keep doing exciting stuff, you'll be one of the sharpest people out there (and running circles around young people falling flat on mistakes you've already made). For your future, interesting work matters, and a PhD is a powerful asset (though it doesn't guarantee anything) in the battle for the scarce interesting projects.