Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : runkit Functions : runkit_import

runkit_import

Process a PHP file importing function and class definitions, overwriting where appropriate (PECL runkit:0.7-0.9)
bool runkit_import ( string filename [, int flags] )


Code Examples / Notes » runkit_import

php

When using this function to override an existing class, you need to be careful in cases where the new definition 'extends' another class - it won't work.
For example,
<?php
// File 1
class BaseCls { }
class TestCls extends BaseCls {
 function hi () { echo "Hi"; }
}
runkit_import('test2.php');
?>
<?php
// File 2
class TestCls extends BaseCls {
 function hi () { echo "Hi again!"; }
}
?>
will NOT work. In file two, you need to omit the 'extends BaseCls'. Note however, that anything from BaseCls will still be in TestCls since it was defined originally in file 1.
From what I can tell, runkit_import defines and overwrites elements - however it does not delete.


info

Note that reloading classes does not work, when you're using this extension on the PHP Command Line Interface.

bbisgod

I was experiencing problems using this function on a script. I discovered through trial and error that you CANNOT reload a function (or method of a class) if it has been called (e.g, its present in the debug_backtrace). Also you cannot redeclare a function that is used by set_error_handler.
The reasons are logical, but it took me a good 2 days of debugging to find it, hope this saves someone a headache.


Change Language


Follow Navioo On Twitter
Runkit_Sandbox
Runkit_Sandbox_Parent
runkit_class_adopt
runkit_class_emancipate
runkit_constant_add
runkit_constant_redefine
runkit_constant_remove
runkit_function_add
runkit_function_copy
runkit_function_redefine
runkit_function_remove
runkit_function_rename
runkit_import
runkit_lint_file
runkit_lint
runkit_method_add
runkit_method_copy
runkit_method_redefine
runkit_method_remove
runkit_method_rename
runkit_return_value_used
runkit_sandbox_output_handler
runkit_superglobals
eXTReMe Tracker