在调用之前检查未定义的PHP方法?

What can I use other than if(!empty( $product->a_funky_function() )) to check if the method is empty before calling it?

I've tried method_exists() and function_exists() and a whole plethora of conditions. I think the issue is that I need to have my $product variable there.

Please help.

A fairly common pattern is to have two methods on your class, along the lines of getField and hasField. The former returns the value, and the latter returns true or false depending whether or not the value is set (where "set" can mean not null, or not empty, or whatever else you might want it to mean).

An example:

class Foo
{
    /** @var string */
    private $field;

    /**
     * @return string
     */
    public function getField()
    {
        return $this->field;
    }

    /**
     * @return bool
     */
    public function hasField()
    {
        return $this->getField() !== null;
    }
}

This would then be used like:

if ($foo->hasField()) {
  $field = $foo->getField();
  ...
}

Often, like in this example, the has... method often just delegates to the get... method internally, to save duplicating the logic. If the getter contains particularly heavy processing (e.g. a database lookup or API call), you might want to factor in ways to avoid performing it twice, but that's a bit out of scope.

You need absolutely to call it so it can compute the value which it will return, so I think there is no other way to know if it will return something not empty without calling it...

You have to call it.

$result = $product->getFunction();
if(!empty($result)) {
//your code here
}