Example to use Class, Constructor, Functions and Objects in PHP programs

In this post you are going to learn about the use and the concept of Class, Constructor, Functions and Objects in PHP.

Please find the below example for the same.

 PHP example inside HTML tags
A simple example page in php : use of class, constructor and methods or functions...
*/ ?>
result //$this-> is used to access methods or any thing dynamically function __construct(){ echo 'This is php constructor'; } //method or funtion name starts with function then the name of method or funtion function normal(){ echo 'this is php function'; }//end of function normal() //parametrized function in php function set($val){ $a=50; //this will store the multiplication result in the top most declaration of result variable $this->result=$a*$val; }//end of function set($val) function get(){ return $this->result; } }//end of class area ?>
Object creation in php and call to funtions.
'; //call to method or function normal() //for all the dynamic calls we will use $classobject->funcationame() $object->normal(); echo "
"; $object->set(20);//argument or parameter passed to function on call echo '
'; echo $object->get(); /* * the above code can be extended in two lines as: * $value=$object->get(); * echo $value; */ //call in php to dynamic funtion is made by using -> on object. ?>%MINIFYHTMLaca9f24194b1873f7aadc9b7422567a32%

To Run:
1. Save the file as index.php in a folder name abc
2. Move the folder to the root directory of wamp server i.e. www
3. Start the WAMP Server
4. Open your browser and in url type: localhost/abc and press enter
5. You will find your php page running now.

Best Regards!!!

Related Post