PHP:类的方法don';将php文件包含在另一个文件中时不起作用


PHP: Methods of the class don't work when including php file in another one

我创建了一个类,并将文件保存为类。地址.inc.php其具有以下结构:

<?php 
class Address {
public $street_address_1;
public $street_address_2;
public $city_name;
public $subdivision_name;
public $postal_code;
public $country_name;
//display an address in html
public function display() {
    $output='';
    //Street Address
    $output .=$this->street_address_1;
    if($this->street_address_2) {
    $output .= '<br/>'. $this->street_address_2;
     }
    //City, Subdivision, Postal Code
    $output.='<br/>';
    $output.= $this->city_name. ','. $this->subdivision_name;
    $output.= ' '.$this->postal_code;
    //Country
    $output.='<br/>';
    $output.= $this->country_name;
    return $output;
}
}

在我的demo.php文件中,我创建了该类的一个实例:

<?php
require 'class.Address.inc';
echo '<h2> Instanitation Address </h2>';
$address = new Address;
$address->street_address_1 ='555 Fake Street';
$address->city_name = 'Townvile';
$address->subdivision_name ='State';
$address->postal_code ='12345';
$address->country_name='US';
echo '<h2> Displaying Address </h2>';
echo $address->display();
?>

我在浏览器中得到以下错误:

 Fatal error: Call to undefined method Address::display() in C:'xampp'htdocs'dwwphp'demo.php on line 7.

是什么原因造成了问题?

require 'class.Address.inc';

应该是

require 'class.Address.inc.php';