PHP:调用非对象的成员函数[重复](PHP: Call to a member function on a non

编程入门 行业动态 更新时间:2024-10-27 09:38:21
PHP:调用非对象的成员函数[重复](PHP: Call to a member function on a non-object [duplicate])

这个问题在这里已有答案:

在非对象[重复] 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 answers

This 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();

更多推荐

本文发布于:2023-07-20 12:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1199621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   对象   成员   PHP   member

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!