Jump to content

class extend trouble.


Domcsore

Recommended Posts

Hey there, I have 3 files.

 

my index.php

global_reg.php

template.config.php

 

this is what i have:

 

index.php -

<?php 
include_once('classes/global_reg.php');
$global_conf = new globalconf;

/** LOAD ENGINES **/
$global_conf->engineload("template.conf.php");
$global_conf->echome();

?>

 

Then global_reg.php (I wont display it all) -

<?php
class globalconf{
/** DEFINE VARIABLES **/
public $loadengine;


public function engineload($classfile){
	$this->loadengine = array(
							  "class"=>"classes/subclasses/"
							  );
	include_once($this->loadengine['class'].$classfile);
}
}
?>

 

and template.config.php

<?php
class template extends globalconf{

public function echome(){
	echo "Me";
}
}
?>

 

but im getting the error:

 

Fatal error: Call to undefined method globalconf::echome() in index.php on line 7

 

 

Link to comment
Share on other sites

I don't think you're looking at extend in the right way.  It doesn't extend your current class.  It specifies that one class (template) is the child of a parent class (globalconf).  Your parent class doesn't have access to members defined in the child.  So globalconf doesn't magically get the  echome method you define in template.

Link to comment
Share on other sites

my OOP isn't great but I believe you need to create a template object in order to call echome. you can't just include it in your engineload.

 

plus inheritance only goes the other way. i don't think a globalconf object could call a template function unless you casted it? where as a template object would inherit all the globalconf member functions because it extends globalconf.

Link to comment
Share on other sites

I think

 

$global_conf = new globalconf;

 

should be

 

$global_conf = new template;

 

You are creating an instance of template (which extends from globalconf). Thus by having an instance of template, you should have access to globalconf's public methods and properties.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.