<?php // PHP 7 之前版本用法 use some\namespace\ClassA; use some\namespace\ClassB; use some\namespace\ClassC as C; use function some\namespace\fn_a; use function some\namespace\fn_b; use function some\namespace\fn_c; use const some\namespace\ConstA; use const some\namespace\ConstB; use const some\namespace\ConstC; // PHP 7+ 用法 use some\namespace\{ClassA, ClassB, ClassC as C}; use function some\namespace\{fn_a, fn_b, fn_c}; use const some\namespace\{ConstA, ConstB, ConstC}; ?>
Salin selepas log masuk
2 fungsi
// 转换对象为 __PHP_Incomplete_Class 对象 $data = unserialize($foo, ["allowed_classes" => false]); // 转换对象为 __PHP_Incomplete_Class 对象,除了 MyClass 和 MyClass2 $data = unserialize($foo, ["allowed_classes" => ["MyClass", "MyClass2"]); // 默认接受所有类 $data = unserialize($foo, ["allowed_classes" => true]);
Salin selepas log masuk
3. Takrifkan tatasusunan malar melalui takrifkan
<?php define('ANIMALS', [ 'dog', 'cat', 'bird' ]); echo ANIMALS[1]; // 输出 "cat" define("GREETING","Hello you! How are you today?",TRUE); echo constant("greeting"); //返回常量的值 ?>
Salin selepas log masuk
4