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() , );

$MyResult $Math->Sum();

//Here is the visual format to what calculations we have just done

/*
(22 + 7) + (1 + 8) + ( ((22 + 7) + (1 + 8)) / 2) 
*/ 
so theres just a simple tutorial on classes.
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: 5