Good afternoon everyone, I have a question: let's say

class ClassA{ protected $b; function Constructor($ClassB) { $this->b = $ClassB; } function GetRes($param){ return $this->b->GetRes($param); } } $a = new ClassA( new ClassB ); echo $a->GetRes(); 

The example is solely for displaying the essence, the class GetRes implemented in class Б , and class Б may have many descendants with different implementations of GetRes .

The question itself - let GetRes return an array with a set of values ​​required by class А , how to make it so obvious for a programmer who writes a descendant for class Б when writing GetRes , how should parameters be returned?

Thank you very much, sorry if the question seems to be limer.

  • About this speech? function GetRes ($ param) {return $ this-> b-> GetRes ($ param); // must be an array} - Bars
  • Yes, how to set the protocol, what keys should be in the array? - Costa
  • Only $ b is not an array, but an object is Costa

1 answer 1

Option 1: Before the function write PHPDoc

/** * @param mixed $param * @return array(int $key1=> mixed $ret1,int $key2=> string $ret2) */

Option 2: Call the function so that there is no doubt:

 function getArrayOfIntResourceId(){ } 

Option3:

 class A{ function GetRes($param){ $b = $this->b->GetRes($param); if(!B::correctFormat($b)){ print 'Формат неправильный, нужен такой.....'; return null; } return $b; } } 
  • I wanted to know how this is really done, thanks! - Costa
  • PHPDoc is really written and SEPARATELY is written normal documentation with code examples. - knes