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 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM