feat(ext): update extension code and add ctype example

- Replace direct function calls with call() wrapper in ext.cc
- Remove unused php_func.h include
- Add new ctype/main.php example with isAsciiWhitespace function
- Implement proper parameter validation for ASCII range checking
- Add main function to demonstrate ctype space detection usage
master
韩天峰 8 hours ago
parent 13576008d0
commit 27aa8ea930
  1. 23
      examples/ctype/main.php
  2. 7
      examples/project/ext.cc

@ -0,0 +1,23 @@
<?php
function isAsciiWhitespace(int $code) {
// 确保参数在有效范围内
if (!is_int($code) || $code < 0 || $code > 127) {
throw new InvalidArgumentException('参数必须是0-127之间的整数');
}
// 使用chr()将ASCII码转换为字符,然后用ctype_space检测
$char = chr($code);
return ctype_space($char);
}
function main()
{
$list = [9, 10, 12, 13, 32];
foreach ($list as $code) {
if (isAsciiWhitespace($code)) {
echo "The ASCII code $code is a whitespace character.\n";
} else {
echo "The ASCII code $code is not a whitespace character.\n";
}
}
}

@ -1,13 +1,12 @@
#include <phpx.h>
#include <iostream>
#include "phpx_func.h"
using namespace php;
Int php_fn_test(Int a, Int b) {
auto c = a + b;
var_dump(c);
var_dump(php_uname());
call("var_dump", {c});
call("var_dump", {call("php_uname")});
return c;
}
@ -21,4 +20,4 @@ void php_foo____construct(php::Object& this_, php::Int value) {
php::Int php_foo__bar(php::Object &this_, php::Int a, php::Int b) {
std::cout << "hashCode: " << prop_base.str()->h << "\n";
return this_.getProperty(prop_base).toInt() + a + b;
}
}

Loading…
Cancel
Save