I’m quite new to PHP so I don’t know how to solve this error. I’ve been reading the related posts here, but as I said I’m too little experienced to know hot to apply similar solutions 🙁
Here’s the thing:
In my main php file I have:
require_once("SentDocument.php");
$sent = new SentDocument();
$sent->myfunction(param1, param2);
And in SentDocument.php
class SentDocument {
public function myfunction (&$param1, &$param2, &$sError)
{ // inside goes an sql query using param1 and param2
}
}
With this I’m getting:
Call to undefined function myfunction() in … pointing to this line in my main php file:
$sent->myfunction(param1, param2);
The odd thing is: when writting in my main php file:
$sent->
the php editor I’m using shows in a context window myfunction() so I can pick it up .. this means SentDocument.php is well linked and the function is available, right?
So why do I get the error? What am I doing wrong?
Thanks a million!
The function
myfunctionshould be in a class to be able to call using an instance. So:BTW why are you adding those parameters by reference
&. Do you need to change them inside the function.Also:
$sent->myfunction(param1, param2);will result in a syntax error. Ifparam1andparam2are strings you should encapsulate them in quotes (either double or single) of or they are variables they should have a dollarsign ($) in front of it. My guess is that they should be variable since yu are trying to pass them by reference to the function (The ampersand sign&in the function declaration).Another thing you have three required parameters in that function, but you are trying to call the function with only two parameters. So you shoudl either provide the third parameter when calling the function or you should make the third parameter option (by giving it a default value).
In you case I would change the structure to something like the following (semi pseudocode):