View Full Version : extending classes

10-31-2003, 08:14 PM

I'm currently working on a script that has multiple layers (common, business and gui). In my index.php I include the three diffent files each with there own class. What I now would like to do is call to some function of the commonlayer in the business layer and the gui layer. Is it possible to do this directly? Or are there any other ways? Please provide a short code-snippet, for I'm new at this stuff!

Thanx Michiel

11-01-2003, 09:55 AM
ClassName::functionName() would invoke the function of the named class though wouldn't instantiate an object of the class - you could pass the object or object part through the function call if really needed.

if your function simply take a parameter (object or value) and return a manipulated version or somesuch then you'd only need to call something like

$this->return_array = OtherClass::arrayFunction($this->my_array);

If you had extended the base class you could also use parent::function() to call ummm functions within the ummm parent class

I would suggest seeking a few articles on classes and passing objects between classes - maybe also look at phppatterns.com or the advanced php sections at devnetwork.net or sitepoint

11-02-2003, 04:25 PM
you could also aggregate your classes ...

class uber{
function uber(){
$this->common = &new common() ;
$this->business= &new business() ;
$this->gui= &new gui() ;

function whatever(){

there are names and rules for these methodologies , as Okii suggests phppatterns is an excellent resource.

Having said that I for one am very anti 'lets clone JAVA' when it comes to design patterns as I don't personally see the case for it , but its good reading nonetheless.

you can also use .. $this->parent() to instansiate the parent class ... eg

class foo{
function foo(){
$this->yak = 'dude';
function yak(){
return $this->yak ;

class bar extends foo{
function bar(){
echo $this->yak();

$bar = new bar();

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum