duanruoyu6675 2014-03-06 14:09
浏览 46

如何解开laravel课程?

I bind a class like so:

App::bind('Some_Class', 'Other_Class')

So that calls to App::make('Some_Class') will return an instance of 'Other_Class'. However, later on in the script I want to revert this, so that calls to make will now return the original class.

So far, I've tried these:

App::bind('Some_Class', 'Some_Class')
App::bind('Some_Class', NULL)

Neither has worked - they seem to be causing app to store an instance of the class, which is no good, as I need to able to accept arguments. If the constructor is called with no arguments, it triggers a fatal error. So, how do I undo the binding?

I've even tried using reflection:

App::bind('Some_Class', function() {
    $args = func_get_args();
    $app = array_shift($args);
    $reflection = new ReflectionClass( 'Some_Class' );
    return $reflection->newInstanceArgs($args);
});

And it still doesn't work!

  • 写回答

2条回答 默认 最新

  • douju5062 2014-03-06 14:33
    关注

    I believe that

    App::instance('Some_Class', new Some_Class);
    

    will do the reversion

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器