A method is a function that belongs to a class.

Method Calls

method_calls.php
<?php
class Calculator
{
    public function addTax(int $subtotal, int $tax): int
    {
        return $subtotal + $tax;
    }
}

$tax = ;
$subtotal = 40;
$total = (new Calculator())->addTax($subtotal, $tax);

echo "subtotal=" . $subtotal . "\n";
echo "tax=" . $tax . "\n";
echo "total=" . $total . "\n";
<?php
class Calculator
{
    public function addTax(int $subtotal, int $tax): int
    {
        return $subtotal + $tax;
    }
}

$tax = ;
$subtotal = 40;
$total = (new Calculator())->addTax($subtotal, $tax);

echo "subtotal=" . $subtotal . "\n";
echo "tax=" . $tax . "\n";
echo "total=" . $total . "\n";
<?php
class Calculator
{
    public function addTax(int $subtotal, int $tax): int
    {
        return $subtotal + $tax;
    }
}

$tax = ;
$subtotal = 40;
$total = (new Calculator())->addTax($subtotal, $tax);

echo "subtotal=" . $subtotal . "\n";
echo "tax=" . $tax . "\n";
echo "total=" . $total . "\n";
object behavior A method can combine object behavior with changing input from the main script.