Load class object from another Class

Hello,
I have two Models: oxBasket and oxOrders.
Now in oxOrders I have functions that calculates some result and I want to get it in oxBasket.

How I can do loading of oxBasket class in oxOrders?

Thank you.

This is my case:

class Model1{

public $_result = null;

function calculate($num1, $num2){
$res = $num1 + $num2;
$this->_result = $result;
}

function getCalculate(){
return $this->_result;
}

class Model2{
$model1 = oxNew(ā€˜Model1ā€™);
$result = $model1->getClaculate();
}

And I am getting NULL as a result

1 Like

You donā€™t call it.

you should quit your job. seriously.
you donā€™t even know php basics.

first of all: _$result is declared with default value null

When you create new object of class Model1, itā€™s _$result is already null
and when you do this:

you get the default value null because you literally did nothing to change this value.

and second:

find the difference

2 Likes

I cannot call calculate($num1, $num2) from Model2 because I donā€™t have values for needed parameters in Model2. For that I am using getCalculate() function, to be able to return the result.
For that, I have the problem.

As @vanilla_thunder already said:
$res = $num1 + $num2;
$this->_result = $result;

Just find the difference. Itā€™s not that hard. :wink:

You can call calculate in getCalculate. Of course, that depends on when the values are available. When is the function ā€œcalculateā€ called? Before, after or in parallel?
Before? Then you can save values e.g. in a session
Parallel? Then a direct call is possible. Change your model
Later? Bad

I cannot call calculate in getCalculate because values are not available then.
calculate function is called before getCalculate() with directly from the template.