Home > Backend Development > PHP Tutorial > Small example of abstract class in php5

Small example of abstract class in php5

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:56:13
Original
892 people have browsed it
  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. ?>

复制代码


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template