Question

PHP 5.2 reports a "PHP Fatal error: Call to a member function convert() on a non-object" although I specifically check that the object exists and that it contains the required method.

Here is the PHP:

error_log(gettype($userform));
error_log(method_exists($userform, "convert"));

$result = $userForm->convert($arrData);

And here are the appropriate extracts from the error log:

[...] object
[...] 1
[...] PHP Fatal error:  Call to a member function convert() on a non-object
      in /file/name.php on line 140

And here is the method itself:

  public function convert(&$arrData) {
    // Bare-bones code
    return true;
  }

What am I overlooking?

Was it helpful?

Solution

Of what I can see:

error_log(gettype($userform));
error_log(method_exists($userform, "convert")); //$userform

$result = $userForm->convert($arrData); //$userForm

The convert method exists for $userform, but not $userForm, which is what you're calling the method on. PHP variable names are case sensitive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top