开发者

Default value of member variables

开发者 https://www.devze.com 2023-01-04 10:58 出处:网络
What is the default value of class member variables in PHP? Why do I often see: public static $variable = null;

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

Why do I often see:

public static $variable = null;

Wouldn't it be enough:

开发者_C百科
public static $variable;


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消