Fury-Tech Logo
Home  News  Articles  Reviews  Guides  Resources  Forums 
Fury-Tech // Technology news, hardware and game reviews, guides, articles, and resources   
Search:



There are currently 0 members and 21 guests browsing on Fury-Tech.

SEO Scripts
SEO Scripts
List Cleaner Script
Keyword Cleaner
Directory Script
Directory Script
BidVerve Directory
BidVerve Directory
Directory Grow
Directory Grow


Join our community in the tech forums for uncut technology discussion.

Object Abstraction


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.

The class that implements the abstract method must define with the same visibillity or weaker. If the abstract method is defined as protected, the function implementation must be defined as either protected or public.

Example 19-16. Abstract class example

<?php
abstract
class AbstractClass
{
    
// Force Extending class to define this method
    
abstract protected function getValue();

    
// Common method
    
public function printOut() {
        print
$this->getValue();
    }
}

class
ConcreteClass1 extends AbstractClass
{
    
protected function getValue() {
        return
"ConcreteClass1";
    }
}

class
ConcreteClass2 extends AbstractClass
{
    
protected function getValue() {
        return
"ConcreteClass2";
    }

}

$class1 = new ConcreteClass1;
$class1->printOut();

$class2 = new ConcreteClass2;
$class2->printOut();
?>

Old code that has no user-defined classes or functions named 'abstract' should run without modifications.

Join our community in the tech forums for uncut technology discussion.



©2007 Fury-Tech | Tech News, Hardware Reviews, Forums, Guides, and more.

Web Hosting by Intavant

Tech News | Articles | Reviews | Guides | Resources | Tech Forums