热搜:NVER node 开发 php

基础问题,PHP类的定义和调用

2024-09-18 20:05:02
基础问题,PHP类的定义和调用

本帖最后由 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是一个实例化对象。

受教了,谢谢!