The default value for member variables

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

Why do I often see:

public static $variable = null; 

It would not be enough:

 public static $variable; 
+6
oop php
source share
2 answers

That would be, but some people either do not know it, or prefer to be explicit.

A general convention is to initialize to zero when the programmer relies on this null value and does not initialize to null if this element is written before reading.

+8
source share

Setting null explicitly makes the initial value understandable even to people who do not know all the intimate details of PHP.

+2
source share

All Articles