调用我的班级函数的函数 [英] Function to call my class functions
问题描述
我想我没有很好地学习php类的基础知识,但是在这里我会提供一些帮助.
我一直收到此错误:致命错误:在非对象上调用成员函数myFunction()...
基本上我有一个带有功能的php类文件.
在我的主文件中,我已经实例化了类,并且可以通过
成功调用类函数.
Hi,
I guess i did not learn my fundamentals on php classes that well, but I would appreciate some help here.
I have been getting this error: Fatal error: Call to a member function myFunction() on a non-object ...
Basically i have a php class file with functions in it that works.
In my main file, I have instantiated the class and can call class functions successfully by
$myNewClassObject->myFunction("source");
但是,我需要在此处进行一些自动化,因此我很高兴将上面的代码行放入主文件中的另一个新函数中,如下所示:
However, I need to do some automation here so I happily put the line above into another new function in the main file like this:
function repeat()
{
$myNewClassObject->myFunction("source");
}
然后我也从主文件中调用它.这是我收到错误消息的时间.
我做错什么了吗?还是不允许这样做?
我的意思是我可以用一种更原始的方式代替函数来执行此操作,但是对于要创建一个函数来调用类函数的情况,我也很好奇.
抱歉,希望我的解释不要太混乱.
Brian
Then i call it, also from the main file. This is when I get the error message.
Did i do something wrong, or is this not allowed?
I mean i could just do it in a more primitive way instead of a function, but i''m also curious in cases where I want to create a function, to call my class functions.
Sorry, hope my explanation''s not too confusing.
Brian
推荐答案
myNewClassObject-> myFunction("source");
myNewClassObject->myFunction("source");
但是,我需要在此处进行一些自动化,因此我很高兴将上面的代码行放入主文件中的另一个新函数中,如下所示:
However, I need to do some automation here so I happily put the line above into another new function in the main file like this:
function repeat()
{
myNewClassObject->myFunction("source"); }
myNewClassObject->myFunction("source"); }
然后我也从主文件中调用它.这是我收到错误消息的时间.
我做错什么了吗?还是不允许这样做?
我的意思是我可以用一种更原始的方式代替函数来执行此操作,但是对于要创建一个函数来调用类函数的情况,我也很好奇.
抱歉,希望我的解释不要太混乱.
Brian
Then i call it, also from the main file. This is when I get the error message.
Did i do something wrong, or is this not allowed?
I mean i could just do it in a more primitive way instead of a function, but i''m also curious in cases where I want to create a function, to call my class functions.
Sorry, hope my explanation''s not too confusing.
Brian
我认为myNewClassObject是您的课程的一部分吗?而repeat
不是吗?那么如何访问类实例对象呢?在类定义中重复更多,一切都应该很好...
Do I take it myNewClassObject is part of your class? And repeat
is not? So how can it access class instance objects? More repeat into your class definition, and all should be well...
这篇关于调用我的班级函数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!