Jump to content

Pls help me understand oop in php better ? its confusing...pls ?


jd2007

Recommended Posts

here are my questions:

1. What are the things that a class should contain ? i know methods and properties ... what are constructors and destructors ?

2. What should constructors and destructors contain ?

3. What are the functions/built in stuff i can use to do oop ?

4. Where can i find a informative tutorial which doesn't speak of dogs and cats but real php stuff ?

Until recently, i'd hardly used OOP at all. At the moment, im trying to make a graphical calculator(it was the 1st competition, but i didn't have the time, or really the knowledge, to do it back then). I decided to attempt this in an OO manner.

 

Perhaps the way i have structured my code would help you:

 

<?php
class graph(){
//list all the attributes of the class - sizes and scales for x and y, the image handler etc
function __construct($data){//i pass in an array of data to set up the image
	//the constructor creates the image and ouputs the correct header. It sets the attributes
	//of the class from the data passed to it
}
function colours($colour){
	//takes a colour in a string and passes back a colour identifier
}
function drawaxis(){
	//this function drax axis on the graph
}
function plot_equation(){
	//plots the equation we are drawing
}
function parse_equation{
	//parses a string as an equation to make it useable - this is the bit im working on now
}
function __destruct(){
	//outputs the image
}
}
?>

 

The idea behind my usage of constructors and destuctors is that i have put everything that needs to be set up before the class can be used in the contructor - you cant draw the axis/plot an equation until you've created an image etc. The destructor is used to output the image after the last call to the class.

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.