成员变量的默认值 [英] Default value of member variables

查看:84
本文介绍了成员变量的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中类成员变量的默认值是什么?

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

为什么我经常看到:

public static $variable = null;

不够吗?

public static $variable;

推荐答案

可以,但是有些人不知道,或者宁愿露骨.

It would, but some people either don't know that, or prefer to be explicit.

一个常见的约定是,当程序员依赖该空值时,将其初始化为null;如果在读取该成员之前对其进行了写入,则不将其初始化为null.

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.

这篇关于成员变量的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆