I have some php document that's quite large and I only want to require it when its needed.

It can be required first in a function, and later owtside it. It can only be required 1 time, because it creates some variables on every require, and can only make one's per session.

So I must use require_once, and if it's first required in the function, the variables that creates are not avalible outside the function, so = "Undefined variable", and if I use only require() = "Cannot redeclare ..." as I said.

The required document is a third party and I can't change it. What I cant do to make like a Public require?

PD: SORRY, I think the problem is not the function, is that the function is in an other document. I don't see a solution anyways, besides putting all together.