我是 php 的 OOP 概念的新手。我做了一个这样的类
<?Php
class ShopProductWriter {
public function write( $shopProduct ) {
$str = "{$shopProduct->title}: " .
$shopProduct->getProducer() .
" ({$shopProduct->price})\n";
print $str;
}
}
$product1 = new ShopProduct( "My Antonia", "Willa", "Cather", 5.99 );
$writer = new ShopProductWriter();
$writer->write( $product1 );
?>
在这里,我收到了错误,就像Fatal error: Class 'ShopProduct' not found in line 11
实际上我正在从教程中做这个示例一样。有人可以告诉我错误的部分在哪里。我已经完全像教程一样。