From e497d4d08d6a7e5ee46c6bc36713853c536a6dc7 Mon Sep 17 00:00:00 2001 From: Curt Zirzow Date: Mon, 2 Aug 2004 03:12:59 +0000 Subject: [PATCH] Clarify what an abstract class can and cannot do, with example. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@164916 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5/abstract.xml | 51 +++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/language/oop5/abstract.xml b/language/oop5/abstract.xml index bc8b050812..d5c336951d 100644 --- a/language/oop5/abstract.xml +++ b/language/oop5/abstract.xml @@ -1,13 +1,14 @@ - + Object Abstraction - PHP 5 introduces abstract classes and methods. An abstract - method only declares the method's signature and does not provide an - implementation. A class that contains abstract methods needs to be declared - abstract. + PHP 5 introduces abstract classes and methods. It is not allowed to create + an instance of a class that has been defined as abstract. Any class that + contains at least one abstract method must also be abstract. Methods + defined as abstract simply declare the method's signature they cannot + define the implementation. @@ -15,26 +16,48 @@ getValue(); } + } -$o = new ImplementedClass; -$o->test(); +class ConcreteClass1 extends AbstractClass { + + protected function getValue() { + return "ConcreteClass1"; + } + +} + +class ConcreteClass2 extends AbstractClass { + + protected function getValue() { + return "ConcreteClass2"; + } + +} + +$class1 = new ConcreteClass1; +$class1->print(); + +$class2 = new ConcreteClass2; +$class2->print(); ?> ]]> - Abstract classes cannot be instantiated. Old code that has no user-defined - classes or functions named 'abstract' should run without modifications. + Old code that has no user-defined classes or functions named + 'abstract' should run without modifications.