PHP:类成员变量-默认值

PHP:类成员变量-默认值,php,class,Php,Class,考虑到以下几点: <?php class Tiger { static $stripes; } ?> Tiger::$stripes的值是多少?PHP类成员变量的默认值是null Tiger::$stripes将为null <?php class Tiger { static $stripes; } var_dump( Tiger::$stripes ); ?> 因此,这两个$strips的声明是等效的: static $stripes

考虑到以下几点:

<?php

class Tiger {
    static $stripes;
}

?>

Tiger::$stripes的值是多少?

PHP类成员变量的默认值是
null
Tiger::$stripes
将为
null

<?php

class Tiger {
    static $stripes;
}

var_dump( Tiger::$stripes );

?>

因此,这两个$strips的声明是等效的:

static $stripes = null;
  // (equivalent)
static $stripes;

每次你声明一个新变量时,他都会被赋值为null;你应该试着阅读“isset”文档,看看我在说什么。我发布这个问题/答案是因为我厌倦了寻找正确的答案;我发现了5个关于它的堆栈溢出问题,但由于某种原因,甚至没有一个问题能清楚地给出答案。我只是想在搜索引擎中至少有一个明确的答案。
static $stripes = null;
  // (equivalent)
static $stripes;