Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:41:10+00:00 2026-06-17T04:41:10+00:00

I followed this link already before asking – Answer is in JAVA context and

  • 0

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 –

<?php

abstract class grandClass
{
    abstract function grandmethod();

    function __construct()
    {
        echo "I am grandClass constructor";
    }
}

abstract class parentClass extends grandClass
{
    abstract function raiseFlag();

    function grandmethod()
    {
        echo "This is grandmethod!!!","<br />";
    } 

    public function getValue()
    {
        echo "Zero is the blackhole for the numbers!!","<br />";
    }
}

class childClass extends parentClass
{

    function raiseFlag()
    {
        echo "Peaceful thoughts!!","<br />";
    }

}

$myobj = new childClass();
$myobj->raiseFlag();
$myobj->getValue();
$myobj->grandmethod(); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:41:11+00:00Added an answer on June 17, 2026 at 4:41 am

    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:

    abstract class Db
    {
        protected $pdo;
    
        public function __construct($pdo)
        {
            $this->pdo = $pdo;
        }
    
        abstract function select($table, $fields);
    }
    
    class Db_Mysql extends Db
    {
        public function select($table, $fields)
        {
            // Build MySQL specific select query
            // then execute it with $this->pdo
        }
    }
    
    class Db_Pgsql extends Db
    {
        public function select($table, $fields)
        {
            // Build PostgreSQL specific select query
            // then execute it with $this->pdo
        }
    }
    
    // Usage:
    $db = new Db_Mysql($pdo);
    
    $db->select('users', array('id', 'name'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed this link to gzip my php driven website It's working fine but
I followed this link http://www.phpunit.de/manual/3.6/en/database.html there i found some useful details of php db
I followed this link to make use of recent files list but statement below
I followed this link Android get external IP . I am connecting to this
When a button/link is clicked, I want this URL to be called followed by
I followed the directions in this *link and the while the all sites search
I followed this link http://wiki.developerforce.com/page/Getting_Started_with_the_Mobile_SDK_for_iOS#Working_with_the_SDK to as to integrate my iOS App with the
I followed this link iPhone reachability checking but can anyone help me with if
I've asked this already but I need further knowledge. I'm trying to link two
I am truly stumped. I followed this link in learning how to create custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.