Home > Article > Backend Development > How to define classes and operation examples in php
In PHP we can define a class. A class refers to a collection of variables and some functions that use these variables. PHP is a loosely typed language, so overloading by type does not work, nor does overloading by different numbers of parameters. Sometimes it's good to overload constructors in an orientation so that you can create objects in different ways (passing different numbers of arguments). In PHP, this is achieved through classes.
First download a simple definition class library of PHP that we need to use in this course: http://www.php.cn/xiazai/leiku/617
Find it after the download is complete Unzip the php class file we need to our local directory and create a new php file!
After completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "dingyi4.php";//引入类文件 $Wing = new Student; //实例化 $Wing->Input ("Wing","男",33,95,87); $Wing->ShowInfo(); echo "<hr>"; $Paladin = new Student;//实例化 $Paladin->Input ("paladin","女",38,58,59.5); $Paladin->ShowInfo(); ?>
Run the file and the result will be as shown below:
The above is the detailed content of How to define classes and operation examples in php. For more information, please follow other related articles on the PHP Chinese website!