无返回值

类 / 方法

<?php

namespace ClassMethods;

class Counter {
    public $count = 0;

    function incBy($value) {
        $this->count += $value;
    }

    function incByAmount($value, $amount) {
        $this->count += $value * $amount;
    }
}

$counter = new Counter();
$counter->incBy(1);
//counter.count is 1
echo $counter->count, "\n";

$counter->incByAmount(2, 5);
//counter.count is 11
echo $counter->count, "\n";