So I'm reading a physics book and I come across the following passage:

Ok, up to this point I'm fairly confident I'm following along. But then they do the following:

and I have no idea where this comes from. I am guessing here that [itex]p_i=\phi _i(q)[/itex] is only in some sufficiently small region and not the entire space, since they do not explicitly say anything in this regard, so that [itex]p_i-\phi _i[/itex] is not identically zero on the whole space, so I do not know where the above comes from. This is probably something really simple and I'm just being stupid, but any help is greatly appreciated.

If
[tex]\frac{\partial p_i}{\partial q_h} = 0[/tex]
then
[tex]\frac{\partial \phi _i}{\partial q_h} = 0[/tex]
in the region where [tex]p_i=\phi _i[/tex], and outside this region, well, it's identically zero since [tex]p_i[/tex] is not explicitly a function of the [tex]q_i[/tex]'s. Am I on the right track? I don't see where these train-tracks are leading.

Aha! Does this mean that, regardless of where we are in the space, if we have the [tex]p_i[/tex] as a function of the [tex]q_i[/tex] or not, the adding of the term [tex]p_i[/tex] has no effect of the partial derivative because:
If we are in the region where [tex]p_i-\phi _i=0[/tex] the partial derivatives
[tex]\frac{\partial g_s}{\partial q_h} = 0[/tex]
anyway, and if we are outside this region then
[tex]\frac{\partial p_i}{\partial q_h} = 0[/tex]
Is this right?