Skip to main content
deleted 7 characters in body
Source Link

Best way I think

trait ProductTrait { final private function getTable() { if ( empty($this->table_product) ) { throw new \Exception('$table_product must be defined in implementing'. class'__CLASS__); } return $this->table_product; } //From here, just use $this->getTable() instead of $this->table_product } 

If a class using this Trait does not have the table_product property, exception will occur. We dont need anything in that class (and others too) to detect it :)

Best way I think

trait ProductTrait { final private function getTable() { if ( empty($this->table_product) ) { throw new \Exception('$table_product must be defined in implementing class'); } return $this->table_product; } //From here, just use $this->getTable() instead of $this->table_product } 

If a class using this Trait does not have the table_product property, exception will occur. We dont need anything in that class (and others too) to detect it :)

Best way I think

trait ProductTrait { final private function getTable() { if ( empty($this->table_product) ) { throw new \Exception('$table_product must be defined in '. __CLASS__); } return $this->table_product; } //From here, just use $this->getTable() instead of $this->table_product } 

If a class using this Trait does not have the table_product property, exception will occur. We dont need anything in that class (and others too) to detect it :)

Source Link

Best way I think

trait ProductTrait { final private function getTable() { if ( empty($this->table_product) ) { throw new \Exception('$table_product must be defined in implementing class'); } return $this->table_product; } //From here, just use $this->getTable() instead of $this->table_product } 

If a class using this Trait does not have the table_product property, exception will occur. We dont need anything in that class (and others too) to detect it :)