2 回答

TA貢獻1799條經驗 獲得超6個贊
您可以使用閉包綁定方法訪問對象的私有或受保護的屬性。這是一個靜態(tài)函數(shù)示例。
class Helper {
/**
* Helper method to access private
* or protected properties of an object
* using the closure bind method
*/
public static function accessPrivate($object, $property) {
$bind = Closure::bind(
function($prop) {
return $this->$prop;
},
$object,
$object
);
return $bind($property);
}
}
用途:
$code = Helper::accessPrivate($checkAccount, "Code");

TA貢獻1805條經驗 獲得超9個贊
為了從數(shù)組訪問受保護的屬性,您將在下面的代碼片段中找到
$checkAccount = $Accounts->filter("Email eq 'nishanth@gmail.com'");
$getAccountId = $checkAccount[0]->ID;
$getAccountCode = $checkAccount[0]->Code;
由于我嘗試了findWithSelect()和find():
$Accounts->filter("Email eq 'nishanth@gmail.com'")[0]->findWithSelect('ID');
但是沒有產生任何值導致空白值
- 2 回答
- 0 關注
- 174 瀏覽
添加回答
舉報