note 86235 added to language.oop5.basic

From: Date: Wed, 08 Oct 2008 22:49:54 +0000
Subject: note 86235 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-145193@lists.php.net to get a copy of this message
A PHP Class can be used for several things, but at the most basic level, you'll use classes to "organize and deal with like-minded data". Here's what I mean by "organizing like-minded data". First, start with unorganized data. <?php $customer_name; $item_name; $item_price; $customer_address; $item_qty; $item_total; ?> Now to organize the data into PHP classes: <?php class Customer { $name; // same as $customer_name $address; // same as $customer_address } class Item { $name; // same as $item_name $price; // same as $item_price $qty; // same as $item_qty $total; // same as $item_total } ?> Now here's what I mean by "dealing" with the data. Note: The data is already organized, so that in itself makes writing new functions extremely easy. <?php class Customer { public $name, $address; // the data for this class... // function to deal with user-input / validation // function to build string for output // function to write -> database // function to read <- database // etc, etc } class Item { public $name, $price, $qty, $total; // the data for this class... // function to calculate total // function to format numbers // function to deal with user-input / validation // function to build string for output // function to write -> database // function to read <- database // etc, etc } ?> Imagination that each function you write only calls the bits of data in that class. Some functions may access all the data, while other functions may only access one piece of data. If each function revolves around the data inside, then you have created a good class. ---- Server IP: 69.147.83.197 Probable Submitter: 67.150.12.47 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/86235 Del: integrated -- https://master.php.net/note/delete/86235/integrated Del: useless -- https://master.php.net/note/delete/86235/useless Del: bad code -- https://master.php.net/note/delete/86235/bad+code Del: spam -- https://master.php.net/note/delete/86235/spam Del: non-english -- https://master.php.net/note/delete/86235/non-english Del: in docs -- https://master.php.net/note/delete/86235/in+docs Del: other reasons-- https://master.php.net/note/delete/86235 Reject -- https://master.php.net/note/reject/86235 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145193) next »