jd2007 Posted August 9, 2007 Share Posted August 9, 2007 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/64024-pls-help-me-understand-oop-in-php-better-its-confusingpls/ Share on other sites More sharing options...
pranav_kavi Posted August 9, 2007 Share Posted August 9, 2007 These links ll help u, http://www.phpfreaks.com/tutorial_cat/19/Object-Oriented-Programming.php OR http://www.codewalkers.com/c/a/Programming-Basics/Beginning-Object-Oriented-Programming-in-PHP/ Quote Link to comment https://forums.phpfreaks.com/topic/64024-pls-help-me-understand-oop-in-php-better-its-confusingpls/#findComment-319137 Share on other sites More sharing options...
GingerRobot Posted August 9, 2007 Share Posted August 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64024-pls-help-me-understand-oop-in-php-better-its-confusingpls/#findComment-319143 Share on other sites More sharing options...
jd2007 Posted August 9, 2007 Author Share Posted August 9, 2007 thank you so much ginger robot for taking your time to write me that informative example...it helps a lot... Quote Link to comment https://forums.phpfreaks.com/topic/64024-pls-help-me-understand-oop-in-php-better-its-confusingpls/#findComment-319146 Share on other sites More sharing options...
GingerRobot Posted August 9, 2007 Share Posted August 9, 2007 I hope it does help. I do agree that it is hard to find good tutorials and examples of using OOP. I find that things get over-simplified for the sake of example, and end up becoming pointless. Quote Link to comment https://forums.phpfreaks.com/topic/64024-pls-help-me-understand-oop-in-php-better-its-confusingpls/#findComment-319147 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.