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

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

WBOY
WBOYOriginal
2016-06-13 12:38:331014browse

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

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn