It appears that this function still doesn't remove the previous class. I'm not sure what it does to it, but looking at memory usage, it only goes up instead of staying the same or going down (This was when I reloaded a class that was exactly the same).
So that might be something to fix, unless I'm doing something wrong.
runkit_import
(PECL runkit:0.7-0.9)
runkit_import — ファイルから関数やクラスの定義を読み込み、必要に応じて書き換える
説明
bool runkit_import
( string $filename
[, int $flags
] )
include() と似ていますが、関数やクラスの外部に あるコードは無視されます。 また、flags の設定により、 現在実行中の環境内の既存の関数やクラスを自動的に上書きします。
パラメータ
- filename
-
関数やクラスの定義を読み込むファイル名。
- flags
-
RUNKIT_IMPORT_* 系の定数の論理和。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
runkit_import
dabbers
16-Aug-2008 01:58
16-Aug-2008 01:58
Maxdamantus
26-Nov-2007 07:35
26-Nov-2007 07:35
In reply to the comment made by info at lucasvd dot nl:
Runkit WILL reload classes, but the runkit_import must be called from inside an other class or object to do so.
<?php
class reload{
function __construct($file){
runkit_import($file);
}
}
new reload("myclassfile.php");
?>
info at lucasvd dot nl
13-Feb-2007 04:13
13-Feb-2007 04:13
Note that reloading classes does not work, when you're using this extension on the PHP Command Line Interface.
php at ransico dot com
02-Nov-2006 02:17
02-Nov-2006 02:17
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.
bbisgod [at] gmail [dot] com
29-Nov-2005 08:19
29-Nov-2005 08:19
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.
bbisgod [at] gmail [dot] com
29-Nov-2005 07:27
29-Nov-2005 07:27
Heres a nice function to reload the whole program, note, requires PHP5.1:
<?php
function reload() {
$files = get_included_files();
foreach($files as $file) {
if (runkit_lint_file($file)) {
runkit_import($file);
} else {
return false;
}
}
}
?>
