Home  >  Article  >  Backend Development  >  Small example of abstract class in php5

Small example of abstract class in php5

WBOY
WBOYOriginal
2016-07-25 08:56:13863browse
  1. /**

  2. * Define and use php abstract classes
  3. * edit: bbs.it-home.org
  4. */
  5. abstract class Number {
  6. private $value;
  7. abstract public function value();
  8. public function reset() {
  9. $this->value = NULL;
  10. }
  11. }

  12. class Integer extends Number {

  13. private $value;
  14. public function value() {
  15. return (int)$this->value;
  16. }
  17. }

  18. $num = new Integer; /* Okay */

  19. $num2 = new Number; /* This will fail */
  20. ?>

复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn