How to Override Existing Function and Handle the Rest in Magento 2.4

functionmagento2.4

HI I was reviewing the code.
Does :void mean ignore this function in my override?

example:

private function clearIndexTable(): void

When I do override, I copy the original file and modify. The original file has few functions, I only need to modify one of the function. So how do I handle the rest of the functions that doesn't need to be override? I did try to delete those functions that doesn't need to make any change and it breaks. Please help and suggest me what I can do.

Best Answer

:void does not mean ignoring the function in your override. return void means: "Allow functions to declare that they do not return anything at all".

I think you are talking about override methods from a parent method. When you would like to override a method, you only need to override this method, and if this method includes code calls to other private methods you have to copy the other private methods from the parent class to your override class too.

Ex:

In the parent class:

private function clearIndexTable(): void
{
    $indexTable = $this->getIndexTable();
    ....
}

private function getIndexTable(): string
{
    ....
}

In your override class, you have to copy the getIndexTable method too.

Related Topic