- 引入 native_types 类常量定义基本类型 - 添加 std 类提供 int、float、bool 类型转换方法 - 实现 objval 函数进行对象类型验证 - 在 CompilerBase 中添加 nativeTypes 属性控制类型行为 - 修改 getNativeType 方法使用 nativeTypes 判断 - 更新 use 语句解析支持 native_types 导入 - 在 micro_bench 示例中启用严格类型声明 - 添加 str_byte 示例文件测试字符串字节操作pull/1/head
parent
f6cb3278cb
commit
8312de6c73
6 changed files with 89 additions and 51 deletions
@ -0,0 +1,7 @@ |
||||
<?php |
||||
function main() |
||||
{ |
||||
$str = "hello world"; |
||||
$str[2] = "$"; |
||||
var_dump($str); |
||||
} |
||||
@ -0,0 +1,40 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of Swoole-Compiler(AOT). |
||||
* |
||||
* @link https://www.swoole.com/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
class native_types |
||||
{ |
||||
public const type_int = 'int'; |
||||
public const type_float = 'float'; |
||||
public const type_bool = 'bool'; |
||||
} |
||||
|
||||
class std |
||||
{ |
||||
public static function int(mixed $value): int |
||||
{ |
||||
return intval($value); |
||||
} |
||||
|
||||
public static function float(mixed $value): float |
||||
{ |
||||
return floatval($value); |
||||
} |
||||
|
||||
public static function bool(mixed $value): bool |
||||
{ |
||||
return boolval($value); |
||||
} |
||||
} |
||||
|
||||
function objval(mixed $obj, string $class): object |
||||
{ |
||||
if ($obj instanceof $class) { |
||||
return $obj; |
||||
} |
||||
throw new Exception('Invalid object type'); |
||||
} |
||||
Loading…
Reference in new issue