支持declare(strict_types=1);,这样通过zendVM调用其他函数的时候可以触发类型检查 #46
Merged
韩天峰
merged 3 commits from strict_types into master 2 weeks ago
4 changed files with 65 additions and 6 deletions
@ -0,0 +1,38 @@ |
|||||||
|
--TEST-- |
||||||
|
TypePHP enables strict types without a declare directive |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
function checkStrictCaller(string $label): void |
||||||
|
{ |
||||||
|
$callable = 'strlen'; |
||||||
|
try { |
||||||
|
$callable(123); |
||||||
|
echo $label, "=accepted\n"; |
||||||
|
} catch (TypeError $error) { |
||||||
|
echo $label, "=TypeError\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class StrictMethodCaller |
||||||
|
{ |
||||||
|
public function check(): void |
||||||
|
{ |
||||||
|
checkStrictCaller('method'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
checkStrictCaller('main'); |
||||||
|
|
||||||
|
$function = 'checkStrictCaller'; |
||||||
|
$function('function'); |
||||||
|
|
||||||
|
$method = [new StrictMethodCaller(), 'check']; |
||||||
|
$method(); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
main=TypeError |
||||||
|
function=TypeError |
||||||
|
method=TypeError |
||||||
@ -0,0 +1,17 @@ |
|||||||
|
--TEST-- |
||||||
|
declare: strict types 1 |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
declare(strict_types=1); |
||||||
|
function main() { |
||||||
|
$callable = 'strlen'; |
||||||
|
try { |
||||||
|
$callable(123); |
||||||
|
echo "accepted\n"; |
||||||
|
} catch (TypeError $error) { |
||||||
|
echo "TypeError\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
TypeError |
||||||
Loading…
Reference in new issue