I have searched the web, the PHP manual and checked some reference books,
but I can find any satisfactory answer to my question.
Perhaps It my poor grasp of the constructor concept and it's proper application?

Here is the issue:
I have a an existing class constructor definition that I wish to overload.

function__construct( $table, $key, &$db )

    {

        $this->_tbl        = $table;

        $this->_tbl_key    = $key;

        $this->_db        =& $db;

    }

when it is called to extend the class, they use :

function __construct(&$db)
{
    parent::__construct('myTableName','my_id',$db);
}

This is used to pass specific variables to the database object (&$db) ???

I would like to overload this to take one more column argument, so that two "search" variables may be used, the primary key and and indexed column.

what is the correct way to do this?
Also why do they use the parent:: operator, what is theory of operation here?

Recommended Answers

All 2 Replies

You can just make another constructor taking a different number of args for overloading.

parent:: is used to call the parents constructor, which must be done before the child begins to construct. The Employee must be set up before construction of the Janitor can begin. D:)

You can just make another constructor taking a different number of args for overloading.

parent:: is used to call the parents constructor, which must be done before the child begins to construct. The Employee must be set up before construction of the Janitor can begin. D:)

Thanks dfor the reply.
I tried just creating a constructor, but I get "missing" argument errors. I tried by replicating the original in my new sub class and just adding the new arg and variable to the mix as were the others.
No joy!
I tried adding one arg to an "inherited" function, but that didn't work out either.

I may have mis-categorized the function as a class constructor.
It's actually a sub-class constructor, so my changes would be an
overload in the sub-class extension in a third generation, so to speak. The original constructor is just a null set

I thought that the extension should inherit from sub-class, but not down three levels?

Like I said, this is all rather mystifying to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.