普通网友 2013-01-09 18:29
浏览 44
已采纳

Netbeans类型暗示包含内部

So the following is a weird issue and while I'm sure people are going to accuse me of bad practice when it comes to how this behavior is happening, for the sake of the project I'm working on, this is the use case, and I'd love to know if I'm missing something.

I have the following situation

 class foo()
 {
      private $_bar;

      public function __construct($bar)
      {
           $this->_bar = $bar;
      }

      public function doStuff()
      {
           include('doStuffCode.php');
      }
 }

doStuffCode.php:

 $this->_bar->(this is where I'd like to get some type hinting)

I've tried to drop in /* var $this->_bar Bar */ but that doesn't seem to do anything for me. It seems like I can't add type-hinting to a specific class variable. The workaround for now has been to set up a temporary variable called $bar, set the type hinting on it, then use it to get the methods I'm looking for and copying them back into the right context.

I'm curious if I'm just trying something wrong, doing something unsupported, misunderstanding how I should be declaring the javadoc, or have a fundamental misunderstanding of how this type-hinting should be working.

Thanks for the help

  • 写回答

1条回答 默认 最新

  • dongwen7380 2013-01-09 18:32
    关注

    You need to define the type of $_bar in the class

      class foo()
      {
            /**
             * @var Bar
             */
            private $_bar;
    
            public function __construct($bar)
            {
                 $this->_bar = $bar;
            }
    
            public function doStuff()
            {
                 include('doStuffCode.php');
            }
       }
    

    And then in your included file you hint:

    /* @var $this foo */
    

    Which will be the correct way of doing this. All though I'm not sure private variables can be hinted this way due to the scope of the included file contents.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c