将代码从Java转换为PHP格式


Convert code from Java to PHP format.

我是使用PHP的新手。我正在尝试将Java代码转换为PHP,但收效甚微。尤其是声明变量类型long,还将类的对象声明为数组。

public class Company extends User implements Serializable {
private static final long serialVersionUID = 8598447488057067508L;
public String id;
public String companyName;
public String companyCode;
public String avatar;
public Price price;
public List<History> history;
public List<Wall> wallpost;
public boolean isFollowing;
public String toString() {
    return "Company [id=" + id 
            + ", companyName=" + companyName 
            + ", companyCode=" + companyCode 
            + ", avatar=" + avatar + "]";
     }
}

在PHP 中

 <?php
 include "History.php";
 include "Price.php";
 include "Wall.php";
 class Company extends User implements Serializable {
  private static final  long $serialVersionUID = 8598447488057067508L;// get error here
  public $id;
  public $companyName;
  public $companyCode;
  public $avatar;
  public Price $price;//object of Price Class how to declare this?
  public List<History> $history;//object of History Class how to declare this as a List?
  public List<Wall> $wallpost;//object of Wall Class how to declare this as a list?
  public boolean $isFollowing; //how to assign boolean to this variable?
 }

我相信一定有一种方法可以在PHP中进行转换。

谢谢你的帮助。

只将它们定义为数组,就不能定义类型:

<?php
 include "History.php";
 include "Price.php";
 include "Wall.php";
 class Company extends User implements Serializable {
  // Define as constant, include value in quotes
  const serialVersionUID = "8598447488057067508L";
  public $id;
  public $companyName;
  public $companyCode;
  public $avatar;
  public $price;
  public $history = array();
  public $wall = array();
  public $isFollowing;
  public function __construct()
  {
        // Set price
        $price_obj = new Price();
        array_push($this->price, $price_obj);
        // Set history
        $history_obj = new History();
        array_push($this->history, $history_obj);
        // Set wall
        $wall_obj = new Wall();
        array_push($this->wall, $wall_obj);
        // Assign boolean
        $this->isFollowing = true;
  }
 }

您可以在变量/数组中放置任何类型的对象。

final关键字只能在classes上使用,但您可以将其定义为常量。

这可能是一个从强类型语言到弱类型语言的奇怪概念。。。