[英]Ternary Operator - What am I doing wrong?
$profilePic = isset( $userservice->getProfilePic($userid))
? filter($userservice->getProfilePic($userid))
: '<img></img>';
返回錯誤:
Fatal error: Can't use method return value in write context
我在這做錯了什么?
您只能將isset
與變量一起使用,而不能使用函數的返回值,因為isset
不是函數,而是語言構造。
附錄 :有一個投票允許將任意表達式參數傳遞給isset
和empty
,但最終isset
從最終實現中刪除。
僅限isset
並且專門用於變量。 你不需要它來實現功能。 你的三元運算符很好。
請參閱PHP的權威指南isset並為空 。
試試:“
$tempPic=$userservice->getProfilePic($userid);
$profilePic = isset($tempPic ) ? filter($userservicegetProfilePic($userid)) : '<img></img>';
“
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.