I am currently working on bringing my extensions to the current coding standard.

So, when writing a function, normally I would describe it the following way:

protected function exampleFunction(string $name): string|null
   return $name;

But there are some cases, where I dont know, how to "describe" the return value.

For example:

protected function getParentProduct(int $id): ??????
        $parentByChild = $this->catalogProductTypeConfigurable->getParentIdsByChild($id);
        if (isset($parentByChild[0])) {
            //set id as parent product id...
            $parentid = $parentByChild[0];
            return $this->ProductFactory->create()->load($parentid);

So, the function returns a loaded product (built with ProductFactory. But as the Product-class is not explicity at the begin of the class (Magento\Catalog\Model\Product), I dont know, what I should use for the description or if its ok, to just write:

protected function getParentProduct(int $id): Product|null

I know, this is nothing, that would break the code, but I want to use more good habits, when coding my extensions.

1 Answer 1


You can do something like this one :

protected function getParentProduct(int $id): Json

And then return your data into the Json format.

  • So, I change the output of the function, just so I can write a correct comment? oO That does not sound correct....
    – Mario
    Nov 15, 2021 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.