开发者

Override a default php function ? (eval)

开发者 https://www.devze.com 2023-03-25 06:30 出处:网络
we can simply override a default php function by using the following code : namespace blarg; function time() {

we can simply override a default php function by using the following code :

namespace blarg;
function time() {
  echo "test !开发者_StackOverflow";
}
time();

but ! is it possible to override the "eval" functon ?

namespace blarg;
function eval() {
echo "test !";
}
eval();

?

thanks in advance

According to the answeres :

  1. 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 ?)


Note: Because this is a language construct and not a function, it cannot be called using variable functions Manual

So, it can't be overriden as echo/php/include too


namespace blarg;
function time() {
  echo "test !";
}
time();

This does not override the builtin time() function. What this does is create the function blarg\time() -- that is, both time() and blarg\time() exist and can be called, so never was time() overridden.

When you call time() in the blarg namespace, both the builtin time() and local blarg\time() functions are candidates to be called; however, PHP will disambiguate by always calling the most local name, which in this case is blarg\time().

Now, if we ask if it is possible to introduce a function locally named eval(), the answer is no, because eval is a reserved word in the PHP language because of its special meaning -- referred to as a language construct. Other examples of the same nature are isset, empty, include, and require.

0

精彩评论

暂无评论...
验证码 换一张
取 消