Diffraction pattern and uncertainty In case of studying diffraction pattern, we simply do the Fourier transform of the slit function to get the distribution of momentum.
But, suppose a photon is coming towards the slit, and think of the instant  it reaches the slit. For the photon, there is certainly no difference between the instants of


*

*The time it is just about to enter slit

*The time it has reached the slit.


So my question is, how does the photon immediately get the information that they are confined within the slit and distribute their momentum in that way (as in the immediately earlier instant, there was no such distribution of momentum)?
 A: In experiments like this, it is important to remember that a photon isn't just a little ball whizzing around. It is a quantum object that exhibits both particle and wave behavior. It doesn't quite make sense to say "if the photon is in the slit, how does it detect the walls" because its wavelike properties are dominant and can interact with the boundary conditions placed on it, such as being confined to a given space. 
It makes more sense in this context to think of the photon's probability wave being incident on the slit and interacting with it accordingly. You can find a more extensive explanation of this here.
A: There are direct and indirect observations. For example you can count electrons or you can measure the electric potential and derive from this the approximate number of electrons. You can count bolts or knowing the weight of a bolt you can derive the number of bolts in a pile. The difference between direct and indirect measurements are sliding.
To the electron are attributed a particle like behavior as well as a wave like behavior. What do you think, which behavior is more directly observed and which more indirect? In principle this question points in the same direction as your 

... suppose a photon is coming towards the slit,and think of the instant when it reaches the slit.

Shooting single photons and placing a photosensitive plate direct in front of the slit or direct behind the slits, you always observe the particle like behavior of the photon as a small point, much smaller the slits width.
A - more indirect - observation of the wave like behavior is the intensity distribution on a sensitive plate, installed away the slits. Single shooted photons arrive as particles and only after some time you observe on the screen the fringes from which is derived the wave like behavior.
Is there an alternative point of view about what happens in the interaction between the photons and the slits? No, it isn’t.

Anyway, if you want to think ahead, read this question Are there induced currents in the obstacle from the electromagnetic radiation? and Relationship between the material properties of an edge and the fringes behind this edge.
