In computer science in the US, this is just false. Four years is the usual "officially expected" length of a PhD straight out of a bachelors' (which is the most common way to do a PhD in CS in the US). In practice it usually takes longer, sometimes much longer (seven+ years is not unheard of).
In the UK and Europe, shorter PhDs are much more common, in part because you're expected to do a master's before a PhD.
Even for two or three years, I don't think getting a computer science PhD is a good bet if your primary goal is making more money.