Home >Backend Development >PHP Tutorial >Sample code sharing for php initialization object
There are two ways to initialize a class in php. One is to use the function with the same name as the constructor as you said, and the other is to define __construct() (the first two underscores _) as the constructor. These two Except for the different function names, there is no other difference. They are all used to initialize classes. Today I will introduce to you an example of PHP initialization object!
The first step is to download the PHP initialization object class library we need to use in this course: http://www.php.cn/xiazai/leiku/621
Second Step. After the download is completed, find the php class file we need, unzip it to our local directory, and create a new php file!
The third step, after completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "dingyi1.php";//引入类文件 $pc1 = new mypc('家用电脑','台式机');//实例化 echo $pc1->vod()."<br>"; //当$pc1=null;的时候是当前实例操作完成后直接释放出对象 $pic2 = new mypc('公司电脑','笔记本'); echo $pic2->game(); ?>
Run this file and get the result as shown below:
The above is the detailed content of Sample code sharing for php initialization object. For more information, please follow other related articles on the PHP Chinese website!