这个问题在这里已有答案:
在非对象[重复] 8个答案 上调用成员函数这是一个常见的错误,我敢肯定,但我无法弄清楚为什么我会得到它。 我是OOP的新手,但我认为我正在错误地实例化对象?
首先包括:
<?php include("/classes/justgiving.php"); ?>这是绝对正确的,据我所知。
然后我尝试实例化...
$justgiving = new JustGiving();然后当我尝试在对象中运行该方法时:
$justgiving->createAccount($xml);并在类.php文件中:
class JustGiving{ function createAccount($xml) { // function code } }但是我收到以下错误:
Fatal error: Call to a member function createAccount() on a non-object
我有一种感觉,这是一个真正的新错误,而且这是非常明显的。
非常感谢。
This question already has an answer here:
Call to a member function on a non-object [duplicate] 8 answersThis is a common error, I'm sure, but I can't figure out why I'm getting it. I'm new to OOP, but I figure I'm instantiating the object incorrectly?
First the include:
<?php include("/classes/justgiving.php"); ?>Which is absolutely correct, as far I can tell.
Then I try to instantiate...
$justgiving = new JustGiving();And then when I try to run the method in the object:
$justgiving->createAccount($xml);And in the class .php file:
class JustGiving{ function createAccount($xml) { // function code } }But I'm getting the following error:
Fatal error: Call to a member function createAccount() on a non-object
I have a feeling this is a real newb error, and it's something really obvious.
Thanks a lot.
最满意答案
嗯..你写的东西似乎应该有效。 也许你的问题在其他地方?
我可以想到得到这个错误的唯一原因是你在初始化对象之前尝试调用一个方法,例如
$justgiving->createAccount($xml); $justgiving = new JustGiving();Hmm.. what you have written seems like it should work. Maybe your problem is elsewhere?
The only reason I can think of for getting this error would be that you're trying to call a method before initializing the object, e.g.
$justgiving->createAccount($xml); $justgiving = new JustGiving();更多推荐
发布评论