Home > Backend Development > PHP Tutorial > How to define classes and operation examples in php

How to define classes and operation examples in php

黄舟
Release: 2023-03-15 10:52:01
Original
1840 people have browsed it

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();
?>
Copy after login

Run the file and the result will be as shown below:

How to define classes and operation examples in php

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template