Skip to content

Commit

Permalink
Update fn doc
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Feb 27, 2024
1 parent 1df79c9 commit 2cba8f9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/cn/php/fn.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ $rs = $m->test_callback(PyCore::fn(function ($namespace) use ($uuid) {
- 使用 `PyCore::fn()` 包裹了一个 `Closure` 闭包对象作为回调,这里也支持函数名称字符串、对象方法的调用方式
- 回调函数返回了一个字符串,在 `test_callback` 函数中会得到一个 `str` 类型返回值

## Closure 闭包函数
最新的版本中回调函数类型为 `Closure` 为,不再需要使用 `PyCore::fn()` 进行包裹,底层会直接转为回调对象。
但使用 `array``string` 类型的函数名称或类方法作为回调函数时,仍然需要使用 `PyCore::fn()` 进行封装。

```php
# Closure 闭包函数可直接传递
$m->test_callback(function ($namespace) use ($uuid) {
return $uuid;
});

# 字符串函数名作为回调函数,则需要使用 `PyCore::fn()` 封装
function test_fn() {
return $uuid;
}
$m->test_callback(PyCore::fn('test_fn'));
```

## 实例
这里使用了 `Python tkinter` 作为例子:

Expand Down

0 comments on commit 2cba8f9

Please sign in to comment.