第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

致命錯誤: 調(diào)用未定義的方法 ShopProduct編寫器::獲取生產(chǎn)者()

致命錯誤: 調(diào)用未定義的方法 ShopProduct編寫器::獲取生產(chǎn)者()

PHP
皈依舞 2022-09-12 09:18:00
我遇到了一個問題:致命錯誤: 調(diào)用未定義的方法 ShopProductWriter::getProducer() 在 C:\OSPanel\域\zandstra.com\索引.php第 37 行是什么原因造成的?<?phpclass ShopProduct {    public $title;    public $producerSurName;    public $producerFirstName;    public $price = 0;    public function __construct (        $title,        $firstName,        $surName,        $price    )    {        $this->title = $title;        $this->producerFirstName = $firstName;        $this->producerSurName = $surName;        $this->price = $price;    }    public function getProducer () {        return $this->producerFirstName . " " . $this->producerSurName;    }}$product1 = new ShopProduct (    "My Antonia",    "Willa",    "Cather",    "5.99");class ShopProductWriter {    public function write ($shopProduct){        $str=$shopProduct->title . ":" . $shopProduct->getProducer()            . " (".$shopProduct->price.")\n";        print $str;    }}$product1 = new ShopProductWriter("My Antonia", "Willa", "Cather", 5.99);$writer = new ShopProductWriter();$writer->write($product1);
查看完整描述

1 回答

?
回首憶惘然

TA貢獻1847條經(jīng)驗 獲得超11個贊

這里


$product1 = new ShopProductWriter("My Antonia", "Willa", "Cather", 5.99);

你重新創(chuàng)建了 ,直到那時是一個.由此,是一個對象。這沒有方法,它只有一種方法。這是你代碼中的一個拼寫錯誤,我認為你已經(jīng)多次重寫了你的代碼,一些舊的初始化離開了,你應(yīng)該已經(jīng)離開了。在這種形式下,可能做你想要的:$product1ShopProduct$product1ShopProductWritergetProducer()write()


<?php


class ShopProduct {

    public $title;

    public $producerSurName;

    public $producerFirstName;

    public $price = 0;


    public function __construct (

        $title,

        $firstName,

        $surName,

        $price

    )


    {

        $this->title = $title;

        $this->producerFirstName = $firstName;

        $this->producerSurName = $surName;

        $this->price = $price;

    }


    public function getProducer () {

        return $this->producerFirstName . " " . $this->producerSurName;

    }

}


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);


查看完整回答
反對 回復(fù) 2022-09-12
  • 1 回答
  • 0 關(guān)注
  • 70 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號