Results 1 to 1 of 1
-
14th May 2009, 11:40 AM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comPHP Tutorial (Creating Classes)
Heya all,
Im going to show you how to create a PHP5 Class,
the class ill create is a simple logical class that will perform mathmatics on numbers
Here you go.
PHP Code:/*
First you will need to define a class much like a functiion but without the braces () so lets do that now.
*/
class Math{
}
/*
Ok so the first line wis the class Math{ where as Math can be anything because this is the name of the class.
So now we have a class define we need to add some functions so lets have a go.
*/
class Math{
public function Add($first , $second){
}
}
PHP Code:/*
so no we have a function defined and if you are not sure about functions please read my functions tutorial before you continue.
the only thing thats different is the "public" keyword now what this does is allow a script to run the function outside a class, if this was "private" it would not run outside the class.
so lets finish the maths within the Add function
*/
class Math{
public function Add($first , $second){
return ($first+$second);
}
}
PHP Code:/*
so basically we created a function that takes to arguments and adds them together and then returns them.
imk going to go threw the rest of the functions for basic numeracy calculations
*/
class Math{
private $Total = 0; //Use this to hold sum threwout script
public function Add($first , $second);
$this->Add = ($first + $second);
$this->Hold($this->Add);
return $this->Add
}
public function Minus($first , $second);
$this->Minus = ($first - $second);
$this->Hold($this->Minus);
return $this->Minus
}
public function Times($first , $second);
$this->Times ($first * $second);
$this->Hold($this->Times);
return $this->Times
}
public function Devide($first , $second);
$this->Devide ($first / $second);
$this->Hold($this->Devide);
return $this->Devide
}
private function Hold($value){
$this->Total += $value; //
}
public function Sum(){
return $this->Total;
}
}
PHP Code:/*
Now as you can see we have several mathmatical functions available and we have to other functions calles Hold and Sum and a variable thats private.
now what where doing is after every maths function thats run were adding the result of that function into the Hold function witch will then add it to variable Total.
so at the end of every mathmatical calculation we just run the sum function to get our result
*/
$Math = new Math; //Init the class
$Math->Add(22,7);
$Math->Add(1,8);
//We we can devide our result by whatever by using this.
$Math->Devide( $Math->Sum() , 2 );
$MyResult = $Math->Sum();
//Here is the visual format to what calculations we have just done
/*
(22 + 7) + (1 + 8) + ( ((22 + 7) + (1 + 8)) / 2)
*/
litewarez Reviewed by litewarez on . PHP Tutorial (Creating Classes) Heya all, Im going to show you how to create a PHP5 Class, the class ill create is a simple logical class that will perform mathmatics on numbers Here you go. /* Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Tutorial for Creating Vbulletin Theme ?
By warezrock in forum Tutorials and GuidesReplies: 7Last Post: 27th Apr 2011, 09:25 AM -
Tutorial [Creating a PHP Framework] {advanced} (PART 3)
By litewarez in forum Tutorials and GuidesReplies: 1Last Post: 4th Feb 2010, 02:12 AM -
Tutorial [Creating a PHP Framework] {advanced} (PART 1)
By litewarez in forum Tutorials and GuidesReplies: 1Last Post: 30th Jan 2010, 03:37 PM -
PHP Tutorial ( Creating Functions ).
By litewarez in forum Tutorials and GuidesReplies: 9Last Post: 12th May 2009, 04:26 PM -
Tutorial - Creating Signatures in Photoshop
By rich5lee in forum Tutorials and GuidesReplies: 0Last Post: 28th Jul 2008, 05:14 PM
themaRegister - register to forums...
Version 3.51 released. Open older version (or...