Results 1 to 3 of 3

Thread: Abstract Classes in PHP5

  1. #1
    Join Date
    May 2008
    Posts
    30

    Abstract Classes in PHP5

    Hi,

    I am really trying my best to learn PHP5 since last couple of days but I ma unable to understand the concept of Abstract Classes. I just don't understand why does these abstract classes are required?
    Can someone please help me regarding the same?

  2. #2
    Join Date
    Jan 2009
    Posts
    40

    Re: Abstract Classes in PHP5

    Hi,

    I can understand your problem with the abstract classes.
    Please note that an abstract class is a class that is only partially implemented by the programmer. An abstract class is a class with or without data members that provides some functionality and leaves the remaining functionality for its child class to implement. It cannot be instantiated and it can only be extended. Abstract class is prefixed with keyword "abstract".
    Abstract classes are one of the PHP answers to polymorphism and inheritance.

    Syntax:
    Code:
    < ?
    abstract class classname
    {
          //attributes and methods
         .
         .
         abstract function methodname
    }
     
    class derived extends classname
    {
         function methodname
    }
    ?>
    It's application in a program.
    Code:
    < ?
        abstract class employee
       {
           protected $empname;
           protected $empage;
     
           function setdata($empname,$empage)
          {
              $this->empname = $empname;
              $this->empage = $empage;
          }
     
          abstract function outputData();
       }
     
       class EmployeeData extends employee   //extending abstract class
       {
            function __construct($name,$age)
            {
               $this->setdata($name,$age);
            }
     
           function outputData()
           {
              echo $this->empname;
              echo $this->empage;
           }
       }
     
        $a = new EmployeeData("Rabbie","30");
        $a->outputData();
    ?>

  3. #3
    Join Date
    May 2008
    Posts
    29

    Re: Abstract Classes in PHP5

    Hey if you really need to go through the concepts of abstract classes interfaces, polymorphism & inheritance in PHP5 then you must go through the free tutorials available over the net.
    I have found these two tutorials very helpful for you
    oops
    Abstract Class In php5

    I hope this will help.

Similar Threads

  1. Difference between Abstract classes and Interfaces in C#
    By Gallard in forum Software Development
    Replies: 8
    Last Post: 21-05-2012, 11:58 AM
  2. PHP5 - PHP login registration help
    By Orlando in forum Software Development
    Replies: 5
    Last Post: 01-05-2011, 03:24 AM
  3. Table and abstract classes
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 10:49 AM
  4. Use of abstract classes
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 09:07 AM
  5. Destructor in PHP5
    By Duck in forum Software Development
    Replies: 3
    Last Post: 18-03-2009, 12:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,652,133.58016 seconds with 16 queries