2

How i can redefine a function in php with runkit?

$helloWorld = 'echo "Call require_once";';
runkit_function_redefine('require_once', '$word', $helloWorld);
require_once("abc.php");

i seted in php.ini

runkit.internal_override=1

when i run, it show:

Warning: runkit_function_redefine() [function.runkit-function-redefine]: require_once() not found in hhd_debug.php on line 2

Warning: require_once(abc.php) [function.require-once]: failed to open stream: No such file or directory in hhd_debug.php on line 3

Fatal error: require_once() [function.require]: Failed opening required 'abc.php' (include_path='.;xampp\php\PEAR') in hhd_debug.php on line 3

how i can fix it? please help me!

Mr Jerry
  • 1,686
  • 3
  • 14
  • 22
  • This is because your path string(`include_path='.;xampp\php\PEAR'`) is erronous – hjpotter92 Jun 18 '12 at 06:34
  • require_once is probably a language construct (like "unset" and "list") rather than a function, and is probably impossible to overwrite. Why do you want to override it? What are you trying to do? See http://php.net/manual/en/language.oop5.autoload.php for neat ways of including files – Felix Weelix Jun 18 '12 at 06:36
  • i am optimal joomla code for social network and economy electronic. So, i need compare result after optimal (time run and size of it). in joomla include quite more files, so i need assessment each files before and after included – Mr Jerry Jun 18 '12 at 06:46
  • Neat. So you want to optimise Joomla and ensure it's only loading scripts it uses? Not a Joomla person, but guess this could have troublesome consequences - consider leaving Joomla alone and using an opcode cache http://en.wikipedia.org/wiki/List_of_PHP_accelerators – Felix Weelix Jun 18 '12 at 06:58
  • Use a profiler like xdebug instead of screwing with the language itself, which will skew your results anyway. – deceze Jun 18 '12 at 07:04
  • You can go for override_function (http://php.net/manual/en/function.override-function.php) instead if this serves your purpose. – sushil Jun 18 '12 at 07:11
  • **deceze** and **Clancy Hood** are correct, require_once not is function, it is statement, so i can't overwrite it. i tried xdebug before, but it not usefull for now. i am going write a class timmer to calculation time run, get all files included, and remove it if it not need for social network and economy electronic. Any other idea for it? – Mr Jerry Jun 18 '12 at 07:27

1 Answers1

6

I would guess this doesn't work because require_once is a language construct, not a function.
I don't know if there's any other possibility of overriding it, I'd think not.

deceze
  • 510,633
  • 85
  • 743
  • 889