1. 對象中的屬性或者函數是 private 或者是 protect的時候,當實例化這個對象的時候,外部是不能訪問到這個屬性和函數的。

<?php
class TestClass
{
//private $name;
public $name;
public static $staticName;
protected function getName()
{
return $this->name;
}
protected static function getStaticName()
//public static function getStaticName()
{
return self::$staticName;
}
}
$test = new TestClass();
//$getName = $test->getName();
$getStaticName = TestClass::getStaticName();
var_dump(1111, $getStaticName);exit;
?>
View Code