How does object-oriented programming (OOP) in PHP compare to using functions within functions?

Object-oriented programming (OOP) in PHP allows for better organization and encapsulation of code by creating classes and objects. This approach promotes code reusability and modularity, making it easier to maintain and extend the codebase. On the other hand, using functions within functions can lead to complex and hard-to-follow code, as well as potential namespace collisions and code duplication.

// Using Object-Oriented Programming (OOP) in PHP
class Calculator {
    public function add($a, $b) {
        return $a + $b;
    }
}

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

```php
// Using functions within functions
function add($a, $b) {
    return $a + $b;
}

echo add(2, 3); // Output: 5