How can syntax errors be avoided when performing calculations in property declarations in PHP?

To avoid syntax errors when performing calculations in property declarations in PHP, make sure to use simple arithmetic operations and avoid complex expressions or function calls within the property declaration. Instead, perform the calculations outside of the property declaration and assign the result to the property.

class Calculator {
    public $num1 = 10;
    public $num2 = 5;
    public $result;

    public function __construct() {
        $this->result = $this->num1 + $this->num2;
    }
}

$calc = new Calculator();
echo $calc->result; // Outputs 15