In the US, you're looking at paying $20-50k/year, and while most students will get tuition waivers and small stipends, those often disappear if you do any contracting or work on the side to supplement your meager income.
Meanwhile, $100-150k is a reasonable starting total comp right out of school, especially after the recent rash of inflation. And a good worker can realistically double that in the 4-6 years that it would take to get a PhD.
So the opportunity cost is staggering, but wait - there's more. The job market for tech positions has been very hot for the past decade, and the global economy is on the verge of a rebound. If you want to learn about a specific field like ML or aerospace, you can just get a job in that field. Kids graduating today have the option of learning from talented and driven people while earning a reasonable salary.
Research certainly has its place; most of the work that we do is based off of concepts that were pioneered decades ago. But from the perspective of a prospective student in the 2020s, it's a hard sell.
Especially since the current advisor/advisee relationship is rife with perverse incentives. This whole wall of text assumes the best case scenario, where you don't end up in a toxic lab.