以下是一个简单的PHP对象实例,我们将创建一个名为`Car`的类,然后创建这个类的两个实例。

```php

实例php 写对象,PHP实例:如何使用PHP编写对象  第1张

// 定义Car类

class Car {

// 属性

public $brand;

public $model;

public $year;

// 构造函数

public function __construct($brand, $model, $year) {

$this->brand = $brand;

$this->model = $model;

$this->year = $year;

}

// 方法

public function displayInfo() {

echo "