Jump to content

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


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.

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.