All electronic devices (and everything else, also) will fail at some time in their life. Most will last longer than 2 years, but it depends a lot on how well they were cared for; how many times was it dropped, for example? But random failures happen also. And a lot of users replace their phones every couple of years, anyway. I had an iPhone 4S that I used for 3 years that I passed on to my wife who used it for 3 more. It was still working when she finally got an iPhone 8, so we passed it on to a charity (I did replace the battery once). She also used my 5 year old iPad 2 until I talked her into getting a current model. The iPad 2 still works, however, 7 years later. OTOH, I had a 7+ that stopped charging after 18 months, but, as I had AppleCare+ it was replaced under warranty.
So how long with a phone last is similar to how long will a car last. I'm still driving my 16 year old Prius with 100,000 miles (or actually my wife is). It works great. On the original traction battery. I don't expect an iPhone (or any phone) to last that long, however.