M
M
Mikha Pankratov2017-10-05 08:51:19
PHP
Mikha Pankratov, 2017-10-05 08:51:19

How to achieve the creation of immutable structures?

Good afternoon,
I can not understand how I can do this in this example ..

$a = RUB(10)->mul(5); 
$b = ($a->add(USD(5))->sub(RUB(3)))->mul(2);
$b->describe(); // возвращает строку '((10RUB) * 5 + 5USD - 3RUB) * 2'
$a->describe(); //(10RUB) * 5

I did but I change the object in the course of work,
as a result in $a->describe(); I got a value higher than and i.e. '((10RUB) * 5 + 5USD - 3RUB) * 2'
but //(10RUB) * 5
Thank you all for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-10-05
@frmax

Oh somehow not correctly at you the immutable object is implemented. Read how to organize them in PHP, for example in this article

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question