Re: Using a Resource as a Class Property



..oO(Sanders Kaufman)

OK - that was weird, and took some debugging.
I knew there was *something* about scope to deal with here.

I'm aggragating the database object into a base class, and then creating
other classes that "extend" that base class.

HOWEVER, in order to do that, I had to move the instantiation(?) of the
database class into the extended class.

This shouldn't be necessary, as long as you're correctly calling the
inherited methods from your derived class when necessary. Additionally
in PHP 4 there are no visibility options as in PHP 5 (public, protected,
private), so all member variables and methods are always public and
accessible from everywhere.

When I had it in the base
class, the class that extended it could not see the database properties
and functions.

Hmm. Let's take your first example again (shortened):

class my_baseclass {
var $Database;

function my_baseclass() {
$this->Database = new my_database();
...
}
}

Now let's extend it:

class my_childclass extends my_baseclass {
}

This class will pretty much do the same as the base class, since no
methods are overwritten. But if you want to overwrite some methods to
extend their functionality, you should always also call the inherited
method. Let's assume you overwrite the constructor:

class my_childclass extends my_baseclass {
function my_childclass() {
// first call parent constructor or we won't have a database ...
parent::my_baseclass();
// then do some other stuff
...
}
}

Micha
.



Relevant Pages

  • Re: Using a Resource as a Class Property
    ... Instantiating? ... I'm aggragating the database object into a base class, and then creating other classes that "extend" that base class. ...
    (comp.lang.php)
  • Re: Need help restoring a SharePoint config database corruption
    ... You cannot run SharePoint without having extended a Virtual Server. ... don't extend any Virtual Servers, ... If the content database is still intact, all your data is still there. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: OOP and Pear::DB
    ... this method is very enlightening. ... I didn't think to take the database as the base class and extend my ...
    (comp.lang.php)
  • Re: How to connect to existing content DB after new WSS setup?
    ... Don't edit the Config DB manually. ... When you first extend the site you will ... There is no option to type in an existing database. ... Under Virtual Server Management you will find Manage Content ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: Embed or Extend
    ... Stored procedures are stored in the database itself, ... What Postgres calls PL/Python works because it embeds Python in Postgres. ... there are interface wrappers for Postgres that extend Python with a database. ...
    (comp.text.tex)