• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 4年前 (2022-01-24) 11次浏览 已收录 0个评论

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 <strong>*本文来@源gao@daima#com搞(%代@#码@网2</strong><pre>搞代gaodaima码

$objectValue;
}
}

?>

报错如下

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

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

发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址