The difference between NULL and no value assignment in the PHPClass attribute

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.