Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: Never - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Never

2025-04-18

Never

never 是仅用于返回的类型,表示函数不会终止。这意味着它要么调用 exit(),要么抛出异常,要么无限循环。因此,它不能是联合类型声明的一部分。自 PHP 8.1.0 起可用。

never 是类型理论中的最底层类型。这意味着它是其它所有类型的子类型,并在可以在继承期间替换其它任何返回类型。

添加备注

用户贡献的备注 2 notes

up
27
ali1289445 at gmail dot com
1 year ago
<?php

function sayHello(string $name): never
{
echo
"Hello, $name";
exit();
// if we comment this line, php throws fatal error
}

sayHello("John"); // result: "Hello, John"
up
1
dcfynn at icloud dot com
4 months ago
I think the description should be corrected from return-only to non-return function since the context is now misleading

官方地址:https://www.php.net/manual/en/language.types.never.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3