dtj88302 2013-05-06 09:42
浏览 9
已采纳

类声明中的静态与函数中的静态

class A{

  static $var = true;

  function f(){

  }

}

vs

class A{

  function f(){
    static $var = true;

  }
}

There doesn't seem to be any difference. Are there any advantages of using one over the other?

Note that $var would be used in the f() function only. I understand that declaring it in the class header is required if the variable needs to be used in multiple functions

  • 写回答

2条回答 默认 最新

  • douzong2206 2013-05-06 10:04
    关注

    In the later example you may only use the var inside the f function. The other is accessible anywhere from inside the class A::var or outside A::var

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块