When PHP defines the Class attribute, what is the difference between NULL and no value assignment? For example: Code 1: {code...} Code 2: {code...} What is the difference between the above Code? When PHP defines the Class attribute, what is the difference between NULL and no value assignment?
For example:
Code 1:
class Base{ protected $_db = NULL; function __construct() { }}
Code 2:
class Base{ protected $_db; function __construct() { }}
What is the difference between the above Code?
Reply content:
When PHP defines the Class attribute, what is the difference between NULL and no value assignment?
For example:
Code 1:
class Base{ protected $_db = NULL; function __construct() { }}
Code 2:
class Base{ protected $_db; function __construct() { }}
What is the difference between the above Code?
It is a good habit to declare the initial value of a variable.
No difference
Http://php.net/manual/zh/language.types.null.php
Class Base {protected $ _ db = NULL; function _ construct () {}}$ B = new Base (); var_dump ($ B); output: object (Base) #1 (1) {["_ db": protected] => NULL} class Base {protected $ _ db; function _ construct () {}}$ B = new Base (); var_dump ($ B); also output: object (Base) #1 (1) {["_ db ": protected] => NULL} but when you do not define a variable $ var; $ var_dump ($ var) directly in the class, a warning of Notice: Undefined variable: is returned, but the output is null.