dousu8456 2017-05-05 09:49
浏览 109
已采纳

函数声明在__constructor的类中,而PHP中没有关键字public

I haven't got a better clarity after a long search about, using keyword public in a __constructor function in a PHP class.

  1. People saying __constructor itself is public by default. So I don't have to use mention as public.
  2. Will there be no change if I mention or don't as public in public function __constructor in PHP?
  3. what is the best practice of declaring a __constructor in PHP? with or without the keyword public?
  4. what are the disadvantages or issues that I will face if I don't mention the keyword public in-front of a public function __constructor?
  • 写回答

4条回答 默认 最新

  • dtdh11647 2017-05-05 10:08
    关注

    __constructor is a method. Visibility of methods is described in PHP Doc as:

    Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public.

    So there is no need to write 'public' visibility for public methods.

    But still I prefer to write explicitly visibilities (even 'public') for methods - code is more obvious for everyone.

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

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题