基礎問題,PHP類的定義和調用

來源:互聯網
上載者:User
本帖最後由 bulls5988 於 2013-07-22 15:35:23 編輯

在sub.php裡面定義了一個類,裡面就有一個函數。因為傳回值要轉成XML所以不能直接在函數裡輸出。現在測試的時候在test.php上調用現在提示錯誤資訊:

Catchable fatal error: Object of class massage_gether could not be converted to string in \xampp\htdocs\asxmt_wx\test.php on line 26


請問在類的定義輸出和調用哪步我做的有問題?

sub.php代碼class massage_gether{function main_menu_test() {//主菜單內容$mytext =  '歡迎光臨總店公眾服務平台,請選擇數字您所需的服務:'."\n".'(1)會員卡積分查詢'."\n".'(2)商場活動查詢'."\n".'(4)其他服務'."\n".'輸入@可以返回主菜單';return $mytext;}}


index.php代碼include("sub.php");$shower =  new massage_gether();$shower -> main_menu_test();echo $shower; //這個是第26行


回複討論(解決方案)

$shower = new massage_gether();
echo $shower -> main_menu_test();
$shower是一個執行個體化對象。

受教了,謝謝!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.