Maison  >  Article  >  développement back-end  >  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:33976parcourir

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

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn