In what scenarios can a function be defined correctly in PHP but not recognized when called within a class method, and how can this issue be resolved?
When a function is defined outside of a class in PHP, it may not be recognized when called within a class method due to scoping issues. To resolve this, you can use the `global` keyword to explicitly specify that the function is in the global scope. Example:
function myFunction() {
return "Hello, World!";
}
class MyClass {
public function myMethod() {
global myFunction;
echo myFunction();
}
}
$obj = new MyClass();
$obj->myMethod(); // Output: Hello, World!