On the Lavrentiev Phenomenon and the Validity of Euler-Lagrange Equations for a Class of Integral Functionals