Default value of member variables

前端 未结 2 1484
南方客
南方客 2021-01-12 01:16

What is the default value of class member variables in PHP?

Why do I often see:

public static $variable = null;

Wouldn\'t it be eno

相关标签:
2条回答
  • 2021-01-12 01:40

    It would, but some people either don't know that, or prefer to be explicit.

    A common convention is to initialize to null when the programmer relies on that null value and do not initialize to null if that member is written to before being read.

    0 讨论(0)
  • 2021-01-12 01:47

    Setting it to null explicitly makes the initial value clear even to people who don't know every intimate detail of PHP.

    0 讨论(0)
提交回复
热议问题