I made a second class that inherits everything from the first. It should display the result of the sum () method in the square, but this does not happen, because initially the result property has a value of 0 , I need to assign this property the value of $ firstNumber but I don’t know how?
<?php header('Content-Type: text/html; charset:utf-8'); error_reporting(-1); class CalkSum{ public function __construct($firstNumber){ $this->firstNumber = $firstNumber; } public $result = 0; public function sum(){ for($i = 0; $i < func_num_args(); $i++){ $this->result = $this->result+ func_get_args()[$i]; } return $this->result + $this->firstNumber; } } class SumSquare extends CalkSum{ public function square(){ return $this->result * $this->result; } } $ob2 = new SumSquare(100); $res1 = $ob2->sum(1,2,3); echo 'Результат сложения ' . $ob2->firstNumber . ' + аргументы = ' . $res1; echo '<br>'; echo $res1 . ' в квадрате = ' . $ob2->square(); 106 * 106 should output 11236, and it outputs 36 from me