我發現在php.net類變量範圍和visiblilty
class MyClass
{
public $public = 'Public';
protected $protected = 'Protected';
private $private = 'Private';
function printHello()
{
echo $this->public;
echo $this->protected;
echo $this->private;
}
}
$obj = new MyClass();
echo $obj->public; // Works
echo $obj->protected; // Fatal Error
echo $obj->private; // Fatal Error
$obj->printHello(); // Shows Public, Protected and Private
這對於工作
是罰款的代碼,但如果我用,如果爲:
class MyClass
{
public $public = 'Public';
protected $protected = 'Protected';
private $private = 'Private';
function printHello()
{
echo $this->public;
echo $this->protected;
echo $this->private;
}
}
$obj = new MyClass();
print_r($obj);
它給我所有的類變量的信息。
因此,如果我將它用作保存我的數據庫信息的API代碼和類變量,如何保護我的類變量信息。
謝謝你的回覆! –