refactor(examples): 更新PHP示例中的类型声明和代码结构

- 为Foo类的属性$b添加int类型声明
- 为read_prop和write_prop方法的参数$n添加int类型声明
- 移除python/sys.php文件开头的注释和无用函数定义
- 重新组织sys.php文件中的代码顺序,将main函数移到合适位置
- 保持原有的系统API调用功能不变
pull/1/head
韩天峰 4 months ago
parent 2912b40b0f
commit 9ed73be36f
  1. 6
      examples/micro_bench.php
  2. 18
      examples/python/sys.php

@ -33,7 +33,7 @@ function simpleicall(int $n)
class Foo {
static $a = 12;
public $b = 0;
public int $b = 0;
const TEST = 23;
static function read_static($n) {
@ -69,13 +69,13 @@ class Foo {
}
}
function read_prop($n) {
function read_prop(int $n) {
for ($i = 0; $i < $n; ++$i) {
$x = $this->b;
}
}
function write_prop($n) {
function write_prop(int $n) {
for ($i = 0; $i < $n; ++$i) {
$this->b = 0;
}

@ -1,8 +1,13 @@
<?php
// python: import sys
use sys;
// python: import sos
use os;
use numpy as np;
function np()
{
print(np::$module);
print(np::version->full_version);
}
function main()
{
@ -13,15 +18,6 @@ function main()
use numpy as np;
function np()
{
print(np::$module);
print(np::version->full_version);
}
$array["hello"] = $a;
$array["world"] = $b;

Loading…
Cancel
Save