PHP 將變數轉換為 foreach 迴圈中的物件型別


這取決於正在使用的 IDE。例如,Netbeans 和 IntelliJ 可以在註釋中啟用 @var 的使用 −

/* @var $variable ClassName */
$variable->

With this, the IDE would know that the ‘$variable’ is a class of the ClassName after the hint ‘->’ is encountered.

此外,可以用一個方法建立 @return 註釋,該方法指定返回型別將是對 ClassName 物件的陣列。此資料可以使用 foreach 迴圈訪問,該迴圈獲取物件的值 −

function get_object_type() {
   return $this->values;
}
foreach( $data_object-> values as $object_attribute ){
}

更新時間: 2020-04-09

808 次瀏覽

開啟你的 職業生涯

完成課程成為認證專家

開始
廣告