亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    php通過(guò)反射修改Exception實(shí)例的message屬性

    php通過(guò)反射修改Exception實(shí)例的message屬性

    通過(guò)查看 Exception 類的源碼可以知道, $message 屬性使用 protect 修飾, 且沒(méi)有提供 setMessage 方法。

    對(duì)于 Exception 實(shí)例應(yīng)該怎么修改 message 呢?答案是: 反射!

    $exception = new Exception('haha'); $message = " - use reflection appended message"; $reflectionObject = new ReflectionObject($exception); $reflectionObjectProp = $reflectionObject->getProperty('message'); $reflectionObjectProp->setAccessible(true); $reflectionObjectProp->setValue($exception, $exception->getMessage() . $message); print_r($exception->getMessage()); haha - use reflection appended message

    通過(guò)以上代碼,能把 $exception 中的 $message 修改掉!反射無(wú)敵。。。

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)