> ## Content Index
> Fetch the complete content index at: https://scriptcrunch.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# PhP Classes and Objects Explained
- URL: https://scriptcrunch.com/php-classes-and-objects-explained/
- Published: 2013-05-07T15:18:00.000Z
- Updated: 2026-06-23T08:56:26.000Z
- Author: Scriptcrunch Editorial
- Tags: #Migrated-1758801465347, #wp, #wp-post, #Import 2025-09-25 11:57

Class: Class is a way to organize the data. For instance , you want to write a program to display the names of parts of a car. What you can do is you can echo out all the part names of a car. So , now you want to display the part names of 10 cars . Now echoing out sounds little bitter, isnt it? here is where object oriented concepts comes in to play. To solve the problem, we use the class concept. here int this [tutorial](https://scriptcrunch.com/tag/tutorials/) i have created a class called coder, which contains the coders details. So we create a class template called coder. Then we create many instances of the coder class to display the details of various other coders.  
  
Class systax:  
  
<?php  
class coder{  
{  
public $variable;  
private $variable;  
  
public fucntionS()  
{  
*//your code here*  
}  
}   ?>  
 
Object: Object is an instance of the class. class is like a template and we can create many copies of the class using the object.  
  
Object Syntax:  
  
<?php                                                                             $object1 = new coder() *//here we create an on bject of type coder class using the keyword new. It means we create a object variable to connect to the class coder* ?>

  
Example:

<?php  
class coder {      
public $name;  
public $language;  
public $position;       
    function showDetails($a, $b ,$b)  
    {      
    $this->name =$a;      
    $this->language =$b; *//$this keyword assigns the parameter value to the      variables declared as public.*      
    $this->position =$c;  
}  
    function thisTest($a)  
    {  
      $this->name = $a; *//$this keyword here assigns the parameter to the        variable name associated with function thisTest.* 
 *}*   
}  
?>  
<html>  
    <title>OOP demo</title>  
<body>  
    <h1>This ia a php object oriented demo</h1>  
    <?php      
    $person1 = new coder(); //$person1 object created with new keyword      
    $person1->showDetails("michael","php","junior programmer"); //using the person object , here we pass the parameters to the showDetails fucntion.    
    echo "<div style='background-color:blue'>".$person1->name."&nbsp&nbsp".$person1->language."</div><br/>";  
    $person1->thisTest("libin");      
    echo "<div style='background-color:blue'>".$person1->name."</div>";      
    ?>  
</body>  
</html>