How does the execution of functions in object-oriented PHP differ from procedural programming?

In object-oriented PHP, functions are encapsulated within classes and are called methods. This allows for better organization and structure of code. In procedural programming, functions are standalone and can be called anywhere in the code. Object-oriented PHP promotes code reusability and inheritance through classes and objects, while procedural programming relies on functions for code execution.

// Object-oriented PHP example
class Calculator {
    public function add($a, $b) {
        return $a + $b;
    }
}

$calc = new Calculator();
echo $calc->add(2, 3); // Outputs 5

// Procedural PHP example
function add($a, $b) {
    return $a + $b;
}

echo add(2, 3); // Outputs 5