Jump to content

Class extention inheriting values


cooldude832

Recommended Posts

I don't know if I"m doing this right so let me explain first

 

I have a class called stats . It is basically my page container for my statistics page so it has the primary key of the database item we're stating up and its owner's name etc

 

I want to make a new extending class called graphs that can draw graphs.

 

In the graphs class I want it to inherit all the data already set forth in a defined stats class  (in php4)

 

example

<?php
class stats{
var $var1 = "Bob";
}
class graphs extends stats{
}
$stats = new stats();
$stats->var1 = "George";

$graph_1 = new graphs();

#I want $graph-1->var1 to be George
?>

 

make sense?

Link to comment
https://forums.phpfreaks.com/topic/116931-class-extention-inheriting-values/
Share on other sites

The point of th extended class is because i want to generate multiple graphs but using different data sets that are still common the original stats object (like its primary key from mysql and other data)

 

I can just important saying

$graph->var1 = $stats->var1

 

I'll figure it out.

so you have a stats class which has the data you wish to graph, and you want to be able to make many graphs from the data contained within stats?  So you want to make the graph class an child of the stats class?  extends lets you share common methods and attributes for the same instance.

 

I would create a stats class (sounds like you have it already) and define a public $graphs = array(); attribute.

 

Then create a graph Rendering class.  If this class needs to be unique to the datatype, use the extends here.  This might also be a good place for an abstract class.

 

Now in the stats class, add methods to create new graph objects and assign their reference to the $graphs array.  If you need different methods to handle the processing of the different stat types, then extend stats.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.