dongque1462 2011-06-26 11:59
浏览 14

现有类对象中的PHP匿名函数声明[重复]

Possible Duplicate:
Initialize class property with an anonymous function

I've been programing PHP for quite a while, and PHP 5.3 anonymous functions are one of those thinks that help you out a lot while building some simple scripts. However, I cannot understand why would the following example won't work?

$db         = new PDO([..]);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->die    = function($str){ die(var_dump( $str )); };

$db->die('[..]');

After all, all I do is declare anonymous function on ->die property of PDO instance. This kinda makes me think this is a PHP bug.

  • 写回答

3条回答 默认 最新

  • doumaqing6652 2011-06-26 12:05
    关注

    According to the answers to this question: php Set a anonymous function in an instance

    It is by design (or a design error). There are some workaround suggestions provided there.

    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码