- 添加magic-constants.phpt测试文件验证__LINE__、__FILE__、__DIR__、__FUNCTION__、__METHOD__、__CLASS__常量 - 添加string-interpolation.phpt测试文件验证复杂表达式的字符串插值功能 - 添加variable-functions.phpt测试文件验证可变函数调用和回调存储功能 - 添加variable-variables.phpt测试文件验证$$var语法并标记为跳过(AOT不支持)pull/1/head
parent
33fe40453b
commit
33725b87d3
4 changed files with 132 additions and 0 deletions
@ -0,0 +1,37 @@ |
||||
--TEST-- |
||||
Magic constants: __LINE__, __FILE__, __DIR__, __FUNCTION__, __METHOD__, __CLASS__ |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class TestMagicConst { |
||||
public function testMethod() { |
||||
echo "__METHOD__: "; var_dump(__METHOD__); |
||||
echo "__CLASS__: "; var_dump(__CLASS__); |
||||
echo "__FUNCTION__: "; var_dump(__FUNCTION__); |
||||
} |
||||
} |
||||
|
||||
function testFunction() { |
||||
echo "__FUNCTION__ in function: "; var_dump(__FUNCTION__); |
||||
} |
||||
|
||||
function main() { |
||||
echo "__LINE__: "; var_dump(__LINE__); |
||||
echo "__FILE__: "; var_dump(basename(__FILE__)); |
||||
echo "__DIR__: "; var_dump(basename(__DIR__)); |
||||
|
||||
testFunction(); |
||||
|
||||
$obj = new TestMagicConst(); |
||||
$obj->testMethod(); |
||||
} |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
__LINE__: int(%d) |
||||
__FILE__: string(%d) "magic-constants.php" |
||||
__DIR__: string(%d) "aot" |
||||
__FUNCTION__ in function: string(%d) "testFunction" |
||||
__METHOD__: string(%d) "TestMagicConst::testMethod" |
||||
__CLASS__: string(%d) "TestMagicConst" |
||||
__FUNCTION__: string(%d) "testMethod" |
||||
@ -0,0 +1,38 @@ |
||||
--TEST-- |
||||
String interpolation with complex expressions |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class Person { |
||||
public string $name; |
||||
public function __construct(string $name) { |
||||
$this->name = $name; |
||||
} |
||||
} |
||||
|
||||
function main() { |
||||
$count = 5; |
||||
$arr = [1, 2, 3]; |
||||
|
||||
// Simple variable interpolation |
||||
$s1 = "count is $count"; |
||||
var_dump($s1); |
||||
|
||||
// Array access interpolation |
||||
$s2 = "first: {$arr[0]}, last: {$arr[2]}"; |
||||
var_dump($s2); |
||||
|
||||
// Property access interpolation |
||||
$person = new Person("Alice"); |
||||
$s3 = "Name: {$person->name}"; |
||||
var_dump($s3); |
||||
|
||||
echo "done\n"; |
||||
} |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
string(10) "count is 5" |
||||
string(17) "first: 1, last: 3" |
||||
string(11) "Name: Alice" |
||||
done |
||||
@ -0,0 +1,41 @@ |
||||
--TEST-- |
||||
Variable functions |
||||
--FILE-- |
||||
<?php |
||||
|
||||
function greet(string $name): string { |
||||
return "Hello, " . $name; |
||||
} |
||||
|
||||
function sum(int $a, int $b): int { |
||||
return $a + $b; |
||||
} |
||||
|
||||
function main() { |
||||
// Variable function call |
||||
$func = 'greet'; |
||||
$result = $func("World"); |
||||
var_dump($result); |
||||
|
||||
// Variable function with multiple args |
||||
$math = 'sum'; |
||||
var_dump($math(3, 7)); |
||||
|
||||
// Callable stored in variable |
||||
$callable = 'strlen'; |
||||
var_dump($callable("test")); |
||||
|
||||
// Array of callables |
||||
$ops = ['sum']; |
||||
var_dump($ops[0](10, 20)); |
||||
|
||||
echo "done\n"; |
||||
} |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
string(12) "Hello, World" |
||||
int(10) |
||||
int(4) |
||||
int(30) |
||||
done |
||||
@ -0,0 +1,16 @@ |
||||
--TEST-- |
||||
Variable variables ($$var) |
||||
--SKIPIF-- |
||||
<?php |
||||
echo "skip The \$\$ syntax is not supported in AOT"; |
||||
?> |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$a = "hello"; |
||||
$$a = "world"; |
||||
var_dump($hello); |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
string(5) "world" |
||||
Loading…
Reference in new issue