首页  >  文章  >  后端开发  >  PHP对象编程有关问题,Call to a member function hello() on a non-object

PHP对象编程有关问题,Call to a member function hello() on a non-object

WBOY
WBOY原创
2016-06-13 12:38:33976浏览

PHP对象编程问题,Call to a member function hello() on a non-object

<?php<br />
<br />
	$instest = new test();<br />
	$insobject = new object();<br />
	$insobject->objectValue = "final";<br />
	$instest->test();<br />
<br />
	class test{<br />
		var $testValue = "testValueins";<br />
		function test(){<br />
			print_r($insobject);<br />
			$insobject->hello();<br />
		}<br />
	}<br />
<br />
	class object{<br />
		var $objectValue = "original";<br />
		function hello(){<br />
			echo $objectValue;<br />
		}<br />
	}<br />
<br />
?>


报错如下

Notice: Undefined variable: insobject in C:\wamp\www\zhebo\test.php on line 11
Call Stack
Notice: Undefined variable: insobject in C:\wamp\www\zhebo\test.php on line 12
Fatal error: Call to a member function hello() on a non-object in C:\wamp\www\zhebo\test.php on line 12

这有什么问题么,怎样才可以达到在实例里引用别的实例里的方法,或者有什么更好地解决方法?
我很急,希望大家可以帮忙。非常感谢啊。非常紧急。第一次用对象的思想编程还不太懂啊。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn