首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

runkit_method_add

(PECL runkit >= 0.7.0)

runkit_method_add - 动态地将新方法添加到给定的类

描述

代码语言:javascript
复制
bool runkit_method_add ( string $classname , string $methodname , string $args , string $code [, int $flags = RUNKIT_ACC_PUBLIC [, string $doc_comment = NULL ]] )
代码语言:javascript
复制
bool runkit_method_add ( string $classname , string $methodname , Closure $closure [, int $flags = RUNKIT_ACC_PUBLIC [, string $doc_comment = NULL ]] )

参数

classname

该方法将被添加到的类

methodname

要添加的方法的名称

args

新创建的方法的逗号分隔的参数列表

code

methodname调用时要评估的代码

closure

定义方法的闭包。

flags

该类型的方法来创建,可以是RUNKIT_ACC_PUBLICRUNKIT_ACC_PROTECTEDRUNKIT_ACC_PRIVATE任选地通过位或具有组合RUNKIT_ACC_STATIC(自1.0.1)

注意:该参数仅用于PHP 5,因为在此之前,所有方法都是公开的。

doc_comment

函数的doc评论。

返回值

成功TRUE或失败时返回FALSE

更新日志

描述

runkit 1.0.4

期望封闭的另一种语法已被添加。

runkit 1.0.4

可选参数doc_comment已添加。

例子

Example #1 runkit_method_add() example

代码语言:javascript
复制
<?php
class?Example?{
????function?foo()?{
????????echo?"foo!\n";
????}
}

//?create?an?Example?object
$e?=?new?Example();

//?Add?a?new?public?method
runkit_method_add(
????'Example',
????'add',
????'$num1,?$num2',
????'return?$num1?+?$num2;',
????RUNKIT_ACC_PUBLIC
);

//?add?12?+?4
echo?$e->add(12,?4);
?>

上面的例子将输出:

代码语言:javascript
复制
16

← runkit_lint

runkit_method_copy →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com