php tutorial - PHP Datatypes Object - php programming - learn php - php code - php script



  • An object is a data type which stores the data and information on how to process that data.
  • If a programmer defines an object in terms of the class, it tends to gather the values with its functions which has been defined in the class.

php code Syntax :

<?php
    class ClassName 
     {
     }
     $class = new Class();
?>
click below button to copy the code. php tutorial - team

  • In PHP, an object must be explicitly declared(i.e defined outside).

Sample Code : a simple php program

<!DOCTYPE html>
<html>
    <head>
        <title>Datatype-Object</title>
    </head>
    <body>
        <?php
            class Wikitechy {
        function hello() {
        $this->model = "www.wikitechy.com";
		  }
		}
       $hai= new hello();
       echo $hai->model;
        ?>
    </body>
</html>
click below button to copy the code. php tutorial - team

php for beginners Code Explanation :

Code Explanation for Datatype Object In PHP

  1. class Wikitechy defines the class with its class name “Wikitechy”.
  2. Function name “function wikitechy()” specifies, which takes one more input in the form of parameter and does some processing and returns a value.
  3. $this->model = "www.wikitechy.com"; specifies the statement www.wikitechy.com .
  4. we create a new object $wiki = new Wikitechy(). The 'new' key word is used to create the object, where its class name is Wikitechy.
  5. In php, echo $wiki->model; specify to display the echo statement “www.wikitechy” on web browser.

php tutorials Sample Output :

output for Datatype Object In PHP

  1. Here in this output,”www.wikitechy.com” will be displayed as output in the browser.


Related Searches to php datatype object