mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 19:58:22 +08:00
Update important.md (#4788)
This commit is contained in:
parent
70ea79fe53
commit
4577f344ed
@ -26,3 +26,59 @@ composer dump-autoload -o
|
||||
# 生成代理类和注解缓存
|
||||
php bin/hyperf.php
|
||||
```
|
||||
|
||||
|
||||
## 避免在魔术方法中切换协程
|
||||
|
||||
> __call __callStatic 除外
|
||||
|
||||
尽量避免在 `__get` `__set` 和 `__isset` 中切换协程,因为可能会出现不符合预期的情况
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function __get(string $name)
|
||||
{
|
||||
sleep(1);
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function __set(string $name, mixed $value)
|
||||
{
|
||||
sleep(1);
|
||||
var_dump($name, $value);
|
||||
}
|
||||
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
sleep(1);
|
||||
var_dump($name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$foo = new Foo();
|
||||
go(static function () use ($foo) {
|
||||
var_dump(isset($foo->xxx));
|
||||
});
|
||||
|
||||
go(static function () use ($foo) {
|
||||
var_dump(isset($foo->xxx));
|
||||
});
|
||||
|
||||
\Swoole\Event::wait();
|
||||
|
||||
```
|
||||
|
||||
当我们执行上述代码时,会返回以下结果
|
||||
|
||||
```shell
|
||||
bool(false)
|
||||
string(3) "xxx"
|
||||
bool(true
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user