There is an abstract MaterialValue class:
abstract class MaterialValue { public function __construct($model){...} protected static function find($id) { $model = OtherClass::find($id); if($model) return $model return false; } } Initially, the task is to ensure that the class, after a successful search, returns its own instance, so the child classes contain the following code:
Product class:
class Product extends MaterialValue { public static function find($id) { $material = parent::find($id); if($material) return new self($material); return false; } } And the class Ingredient :
class Ingredient extends MaterialValue { public static function find($id) { $material = parent::find($id); if($material) return new self($material); return false; } } The code for the find method is identical. The question arises, how to avoid such duplication?
return new static($model);- vp_arthOtherClassyou have here? - Stanislav Belichenkoprotected function find($id), and notprotected static function find($id)? - Stanislav Belichenko