简体   繁体   中英

PHP variable type of class property

Lets take this code as an example:

class foo
{
    private $segments = NULL;
}

$segments will be an array later.

The question:

Should i tell PHP that $segments is an array ( private $segments = array(); ) or leave it as NULL?

What is better?

Thank you!

if you are sure it will be an array later, declare it as an array, if it may change during the program, just keep it as it is.

PHP is non-typed language, so it doesn't really matter, it just a matter of standards and habits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM