我有2个PHP文件:
courier.php
<?php
namespace Shipping;
class Courier
{
public $name;
public $home_country;
public function __construct($name) {
$this->name = $name;
return true;
}
public function ship($parcel) {
// sends the parcel to its destination
return true;
}
public static function getCouriersByCountry($country) {
// get a list of couriers with their home_country = $country
// create a Courier object for each result
// return an array of the results
return $courier_list;
}
}
?>
filephp.php
<?php
//namespace Fred;
require 'courier.php';
//function __autoload($classname) {
// include //strtolower($classname).'.php';
//}
$mono = new Shipping\Courier('Monospace Delivery');
//var_dump($mono);
// accessing a property
echo "Courier Name: " . $mono->name;
// calling a method
$mono->ship($parcel);
$spanish_couriers = Courier::getCouriersByCountry('Spain');
echo $spanish_couriers;
?>
但是当我执行filephp.php时,我收到了这个错误:
致命错误:第19行的D:\ masterphp \ test.php中找不到“Courier”类
第19行是这样的:
$spanish_couriers = Courier::getCouriersByCountry('Spain');
我的范围解决方案有什么问题?
答案 0 :(得分:1)
您缺少Shipping名称空间,它应该是\ Shipping \ Courier :: ...