私が取得:未定義のプライベート変数
未定義の変数:パスワード
未定義の変数:ホスト
未定義の変数:ユーザー
私は、このような通知を取得していますなぜ私はちょうど好奇心、 もののを変数はクラスのプライベートセクションで定義されています。
クラスのプライベートデータメンバをメンバ関数で使用することはできません(これはOOPの全体概念を無効にするためです)。
PHPファイルがある:PHPで
class data_base //helps handling permissins
{
private $host;
private $user;
private $password;
public function feed_data($hst, $usr, $pwd)
{
$host=$hst;
$user=$usr;
$password=$pwd;
}
public function get_data()
{
$info=array("host"=>" ", "user"=>" ", "password"=>" ");
$info['host']=$host;
$info['user']=$user;
$info['password']=$password;
return $info;
}
}
$user1=new data_base;
$user2=new data_base;
$user1->feed_data("localhost", "root", ""); //enter details for user 1 here
$user2->feed_data("", "", ""); //enter details for user 2 here
$perm_add=$user1->get_data();
$perm_view=$user2->get_data();
そのような場合、 'return get_object_vars($ this);'だけでも。 – hakre
@hakreはい。しかし、私が自分自身のために私はそれが好きではない、クラスが後で延長されるとき、それは誤って欲しいよりも多くを公開するかもしれないので。私はより冗長な方法が好きです:) – KingCrunch