Hướng dẫn abstract class constructor php
I followed this link already before asking - Answer is in JAVA context and this for constructor in PHP . Since I am starter, my implementation of my PHP code in OOP concepts, so I am really willing to know about the usage and benefits or when to use constructor in PHP abstract class. Please provide an example in real world context to grab the concept better. PS - Although I am following PHP Manuals to understand OOP concepts but I am finding it little bit hard to understand, any help with the links/blog to follow is really appreciable. My Code -
asked Jan 11, 2013 at 6:03
Constructor in abstract class is the same as in concrete class. Use constructors when they are needed, for example, if you need to intialize some data or assign some resources. I'll give you an example:
answered Jan 11, 2013 at 6:53
LaurisLauris 1,05513 silver badges16 bronze badges 2 Not the answer you're looking for? Browse other questions tagged php oop constructor abstract-class or ask your own question.PHP has abstract classes and methods. Classes defined as abstract cannot be instantiated, and 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. When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child class, and follow the usual inheritance and signature compatibility rules. Example #1 Abstract class example
ConcreteClass1 extends AbstractClass The above example will output: ConcreteClass1 FOO_ConcreteClass1 ConcreteClass2 FOO_ConcreteClass2 Example #2 Abstract class example
ConcreteClass extends AbstractClass
The above example will output: ironiridis at gmail dot com ¶ 14 years ago
mbajoras at gmail dot com ¶ 12 years ago
eat() {
a dot tsiaparas at watergate dot gr ¶ 11 years ago
joelhy ¶ 11 years ago
jai at shaped dot ca ¶ 5 years ago
defaultProductImplementation extends defaultProductAbstraction { shaman_master at list dot ru ¶ 3 years ago
Adapter shewa12kpi at gmail dot com ¶ 1 year ago
__construct($fn, $ln){ swashata4u at gmail dot com ¶ 4 years ago
Base implements Element {/** sneakyimp at hotmail dot com ¶ 14 years ago
jai at shaped dot ca ¶ 5 years ago
myDB implements dbInterface { bishop ¶ 12 years ago
Bar extends Foo { Eugeny at Kostanay dot KZ ¶ 5 years ago
someChildClass extends anotherAbsClass Malcolm ¶ 6 years ago
joebert ¶ 15 years ago
arma99eDAN at yahoo dot com ¶ 7 years ago
pete at surfaceeffect dot com ¶ 12 years ago
designbyjeeba at gmail dot com ¶ 11 years ago
nathan dot vorbei dot tech at gmail dot com ¶ 12 years ago
ClassTwo extends ClassOne { Cheese Doodle ¶ 12 years ago
eeescalona ¶ 14 years ago
write_info(); aloydev2586 at gmail dot com ¶ 7 years ago
rmoisto at gmail dot com ¶ 6 years ago
work(); sam at righthandedmonkey dot com ¶ 8 years ago
cart extends horse { nikola at petkanski dot com ¶ 8 years ago
oliver at ananit dot de ¶ 10 years ago
ProductModel extends AbstractModel balbuf ¶ 6 years ago
|