diff --git a/examples/python/sys.php b/examples/python/sys.php index 0858cb00..6f01698f 100644 --- a/examples/python/sys.php +++ b/examples/python/sys.php @@ -17,8 +17,14 @@ use numpy as np; function np() { - var_dump(np::$module); - var_dump(np::version->full_version); + print(np::$module); + print(np::version->full_version); } +$array["hello"] = $a; +$array["world"] = $b; + +$c = $array["world"]; + + diff --git a/examples/swoole/echo.php b/examples/swoole/echo.php new file mode 100644 index 00000000..218be4f8 --- /dev/null +++ b/examples/swoole/echo.php @@ -0,0 +1,43 @@ +mode === SWOOLE_THREAD ? \Swoole\Thread::getId() : posix_getpid(); +} + +function main() +{ + $serv = new Swoole\Server("0.0.0.0", 9501); + $serv->set([ + 'worker_num' => 2, + 'task_worker_num' => 3, + ]); + + $serv->on('workerStart', function ($serv, $worker_id) { + echo "[#" . getpid($serv) . "]\tWorker#{$worker_id} is started.\n"; + }); + + $serv->on('workerStop', function ($serv, $worker_id) { + echo "[#" . getpid($serv) . "]\tWorker#{$worker_id} is stopped.\n"; + }); + + $serv->on('connect', function ($serv, $fd, $reactor_id) { + echo "[#" . getpid($serv) . "]\tClient@[$fd:$reactor_id]: Connect.\n"; + }); + + $serv->on('receive', function (Swoole\Server $serv, $fd, $reactor_id, $data) { + echo "[#" . $serv->worker_id . "]\tClient[$fd] receive data: $data\n"; + if (!$serv->send($fd, "hello {$data}\n")) { + echo "error\n"; + } + }); + + $serv->on('close', function ($serv, $fd, $reactor_id) { + echo "[#" . getpid($serv) . "]\tClient@[$fd:$reactor_id]: Close.\n"; + }); + + $serv->on('task', function ($serv, $src_worker_id, $task) { + var_dump($task); + }); + + $serv->start(); +} diff --git a/examples/swoole/simple.php b/examples/swoole/simple.php new file mode 100644 index 00000000..cc609b2f --- /dev/null +++ b/examples/swoole/simple.php @@ -0,0 +1,13 @@ +on('receive', function (Server $serv, $fd, $reactor_id, $data) { + echo "[#" . $serv->worker_id . "]\tClient[$fd] receive data: $data\n"; + $serv->send($fd, "hello {$data}\n"); + }); + $serv->start(); +} diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index f41427ef..67bfff10 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1156,12 +1156,12 @@ class CompilerBase extends \PhpAot\Core\Translator // 类型推断,获取对象的类名 if ($this->isNewExpr($right) and $this->isNameExpr($right->class)) { $class = $this->parseIdentifier($right->class); - $this->objects[$var] = $class; + $this->objects[$var] = $this->getNamespacedClassName($class); $type = self::TYPE_OBJECT; } elseif ($this->isFuncCallExpr($right) and $this->isNameExpr($right->name)) { $fn = $this->parseIdentifier($right->name); if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($right->args[1]->value)) { - $this->objects[$var] = $this->parseIdentifier($right->args[1]->value); + $this->objects[$var] = $this->getNamespacedClassName($this->parseIdentifier($right->args[1]->value)); $type = self::TYPE_OBJECT; } elseif (count($right->args) === 1 and $fn === 'any') { $type = self::TYPE_VAR; @@ -1541,7 +1541,7 @@ class CompilerBase extends \PhpAot\Core\Translator $this->fatalError($param, 'Cannot use `resource` as a parameter type.'); // no break default: - $this->objects[$var] = $name; + $this->objects[$var] = $this->getNamespacedClassName($name); return self::TYPE_OBJECT; } } diff --git a/src/cpp/main.cc b/src/cpp/main.cc index b5e653ac..83e4ba27 100644 --- a/src/cpp/main.cc +++ b/src/cpp/main.cc @@ -41,6 +41,8 @@ int main(int cpp_argc, char **cpp_argv) { ProfilerStart("profile.out"); #endif try { + char path_translated[] = "embed"; + SG(request_info).path_translated = path_translated; module->request_startup_func(module->type, module->module_number); } catch (zend_object *e) { rc = EG(exit_status);