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

  • Home
  • SEARCH
  • 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 9136209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:55:22+00:00 2026-06-17T08:55:22+00:00

class hydra { var $dbcon; function __construct($ezSQL){ $this -> dbcon=$ezSQL; } } class user

  • 0
  class hydra {
    var $dbcon;

    function __construct($ezSQL){
        $this -> dbcon=$ezSQL;
    }

  }
  class user extends hydra{
    function foo(){
       echo "bar is: ".$this->dbcon;
    }
  }

I then call:

$hydra      = new hydra($ezSQL);

However, at this point I get the following error:

Fatal error: Cannot instantiate abstract class hydra

How do set up a class that will inherit all of it’s children’s functions so I can do something like this:

$hydra = new hydra("foobar");
$hydra -> foo();

output:

bar is: foobar

  • 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-17T08:55:23+00:00Added an answer on June 17, 2026 at 8:55 am

    You can not get children’s functionality into parent. Just think, does Mom gets her look from her daughter? No. Its the child who inherits from parent.

    The code you have given does not throw any error. But from the error It seems hydra is an abstract class. And as you want to call the childrens method as hydra you should have that method as abstract.

    abstract class hydra {
        var $dbcon;
        function __construct($ezSQL){
            $this -> dbcon=$ezSQL;
        }
        abstract public function foo();
    }
    

    Now you can instantiate user but call the foo() method as hydra. Its help full in Type hinting.

    function dofoo(hydra $h){
        $h->foo();
    }
    $user = new user("bar");
    dofoo($user);
    

    Here the function dofoo sees $h as a hydra instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Foo { public $var ; function __construct($value) { $this->var = $value ; }
class Bar{ public function test(){ $this->testPublic(); $this->testPrivate(); } public function testPublic(){ echo Bar::testPublic\n; }
class base{ public $c = 'c'; public $sub = ''; function __construct(){ $this->sub =
class Foo { private $_bar; public function getBar() { return $this->_bar; } } $b
class person { var $name; var $email; //Getters function get_name() { return $this->name; }
class a{ public void foo(int a){ System.out.println(super); } } class b extends a{ public
class Foo { public: Foo() { do_something = &Foo::func_x; } int (Foo::*do_something)(int); // function
Class Bar inherits from Foo: class Foo(object): def foo_meth_1(self): return 'foometh1' def foo_meth_2(self): return
class Message(db.Model): user = db.ReferenceProperty(User, required=True, collection_name='Message_set') text = db.TextProperty(required=True) I tried this but
Class A { public: NullIt() { this = NULL; } Foo() { NullIt(); }

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.