Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Object++ (int ++)

Is it possible to do object++ in php?

I'am just wondering if something like this is possible, if so how would I achive something like this?

Example:

class x
{
    private $data = 0;
}

$a = new x();
$a++;
like image 881
WhiteFang Avatar asked Jan 21 '26 23:01

WhiteFang


1 Answers

I assume you are trying to increase the variable $data inside the class x?

If so, you will want to do something like this:

class x
{
    private $data = 0;

    public function increaseData()
    {
         $this->data++;
    }
}

$a = new x();
$a->increaseData();
like image 51
Paul Blundell Avatar answered Jan 24 '26 19:01

Paul Blundell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!