we can simply override a default php function by using the following code :
namespace blarg;
function time() {
echo "test !";
}
time();
but ! is it possible to override the “eval” functon ?
namespace blarg;
function eval() {
echo "test !";
}
eval();
?
thanks in advance
According to the answeres :
- eval() is a language construct and not a function, we can’t override it
2.Im not really overriding the time() function in my example. I’m just creating a blarg\time() function
I understood
BUT
Actually i’m writtin sumting like a debugger and i need to change the default behaviour of php functons or some language construct (e.g eval)
Is there anyway to do this ?
Is it possible to change the php source and compile it ? (Is there any specific file to edit ?)
This does not override the builtin
time()function. What this does is create the functionblarg\time()— that is, bothtime()andblarg\time()exist and can be called, so never wastime()overridden.When you call
time()in theblargnamespace, both the builtintime()and localblarg\time()functions are candidates to be called; however, PHP will disambiguate by always calling the most local name, which in this case isblarg\time().Now, if we ask if it is possible to introduce a function locally named
eval(), the answer is no, becauseevalis a reserved word in the PHP language because of its special meaning — referred to as a language construct. Other examples of the same nature areisset,empty,include, andrequire.