Focal length is the distance between the lens and the sensor when the subject is in focus, not the distance to the subject.
The term for the distance to the subject in focus is the focus distance and is measured from the image plane (sensor/film plane). The distance from the lens to the subject is called the working distance which can be significantly less within the context of macro photography. The zone which isappears in focus either side (front and back) of the subject is the depth of field. This varies with the aperture - depth of field increases as the aperture gets smaller (f-number gets larger). All else being equal, depth of field is greater at f/4 than at f/2.
So if you focus on an object 3 meters away with a focal length of 18mm and aperture of f/11, everything from 1m to infinity will be in focus. However, if you focus on the same subject with the same aperture with a focal length of 135mm, the near focus limit is 2.9m and the far focus limit is 3.1m - the depth of field is only 20cm deep, in other words.