谷歌镜像 伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PHP - Manual: runkit_import

来源:网络转载 浏览:23651次 时间:2024-06-21
runkit_lint_file » « runkit_function_rename
  • PHP 手册
  • 函数参考
  • 影响 PHP 行为的扩展
  • runkit
  • runkit 函数

runkit_import

(PECL runkit >= 0.7.0)

runkit_import — Process a PHP file importing function and class definitions, overwriting where appropriate

说明

runkit_import ( string $filename [, int $flags = RUNKIT_IMPORT_CLASS_METHODS ] ) : bool

Similar to include however any code residing outside of a function or class is simply ignored. Additionally, depending on the value of flags, any functions or classes which already exist in the currently running environment may be automatically overwritten by their new definitions.

参数

filename

Filename to import function and class definitions from

flags

Bitwise OR of the RUNKIT_IMPORT_* family of constants.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #1 runkit_import() example

<?php
// import classes entirely
runkit_import('myfile.inc', RUNKIT_IMPORT_CLASSES);

/* import classes, but not imports their static properties
   (RUNKIT_IMPORT_CLASS_STATIC_PROPS is available since 1.0.1) */
runkit_import('myfile.inc', RUNKIT_IMPORT_CLASSES & ~RUNKIT_IMPORT_CLASS_STATIC_PROPS);

/* import only static properties of classes
   (RUNKIT_IMPORT_CLASS_STATIC_PROPS is available since 1.0.1) */
runkit_import('myfile.inc', RUNKIT_IMPORT_CLASS_STATIC_PROPS);
?>
add a note

User Contributed Notes 6 notes

up down 1 dabbers10 years ago 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.
up down 1 bbisgod [at] gmail [dot] com13 years ago 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.
up down 0 Maxdamantus11 years ago 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");
?>
up down 0 info at lucasvd dot nl12 years ago Note that reloading classes does not work, when you're using this extension on the PHP Command Line Interface. up down 0 php at ransico dot com12 years ago 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.
up down 0 bbisgod [at] gmail [dot] com13 years ago 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;
    }
  }
}
?>
add a note

官方地址:https://www.php.net/manual/en/function.runkit-import.php

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net