What are the potential pitfalls of constructing the namespace and class name as a string for dynamic method calls in PHP?

Constructing the namespace and class name as a string for dynamic method calls in PHP can lead to potential pitfalls such as typos, hard-to-debug errors, and security vulnerabilities if user input is used directly in the construction of the string. To avoid these issues, it's recommended to use PHP's built-in functions like `class_exists()` and `method_exists()` to check if the class and method exist before making the call.

// Check if the class exists before constructing the object
if (class_exists($className)) {
    $object = new $className();
    
    // Check if the method exists before calling it
    if (method_exists($object, $methodName)) {
        $object->$methodName();
    } else {
        echo "Method does not exist.";
    }
} else {
    echo "Class does not exist.";
}