当前位置:首页 > PHP > 正文内容

php finally使用

高老师7年前 (2019-05-22)PHP1913
<?php
/**
 * @throws Exception
 */
function curl()
{
    throw  new \Exception('errr');
}

/**
 * getUserInfo
 */
function getUserInfo()
{
    try
    {
        curl();

        return true;
    }
    catch (Exception $exception)
    {
        return true;
    }
    finally
    {
        return false;
    }
}

$rel = getUserInfo();

var_dump($rel);
  1. finally一定会被执行

  2. finally中return会覆盖try和catch的return

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/92.html

分享给朋友:

“php finally使用” 的相关文章

php base64保存为图片偷懒版本

php base64保存为图片偷懒版本

<?php $base64_body = substr(strstr($_POST[base64],','),1); $data= base64_decode($base64_body); file_put_contents($_SERVER[&q...

 php xml字符串转数组,phpxml转数组,php 将xml转换成数组

php xml字符串转数组,phpxml转数组,php 将xml转换成数组

001源码:/*  * $xml_str是xml字符串  */ function  xmltoarray($xml_str) { //禁止XML实体扩展攻击 libxml_disable_entity_loader(true); //拒绝包含...

php迭代器学习

php迭代器学习

php官方已经提供了Iterator(迭代器)接口,通过网上资料的学习,目前看适合超大集合或者数组提取使用。学习一个函数的实现对比内存占用差距.使用迭代器和普通循环实现range()函数。(1).普通循环实现range()函数。function newrange($low, $h...

redis订阅和发布,redis消息订阅与发布, phpredis订阅和发布

redis订阅和发布,redis消息订阅与发布, phpredis订阅和发布

Redis提供了发布订阅功能,可以用于消息的传输,Redis的发布订阅机制包括三个部分,发布者(publisher),订阅者(subscriber)和频道(channel)。 发布者和订阅者都是Redis客户端,Channel则为Redis服务器端,发布者将消息发送到某个的频道,订阅了这个...

php json_encode 使用注意

php json_encode 使用注意

参数中包含gb2312的字符串,返回结果是false或者null(不同PHP版本具有差异性)代码:<?php $dbms = 'mysql'; $host = '192.168.8.8'; $dbName =&n...

pcntl_signal(): Error assigning signal

pcntl_signal(): Error assigning signal

当我想在一个进程中监听kill 和 kill -9命令报了这个错误。//监听kill pcntl_signal(SIGTERM, function () {     posix_kill(0, SIGTERM); });...