在php中怎样创建一个构造函数
1、打开编辑器,为这个程序写上注释内容。#php中如何创建一个构造函数
2、创建一个类test1
3、然后利用__construct来创建一个类。function __construct($name,$age){
4、在构造函数中写上主体内容。function __construct($name,$age){ ec茑霁酌绡ho "my name is".$name." and my age is".$age; }
5、然后实例化一个对象。$t1=new test1();
6、为这个实例化对象传递两个参数。$t1=new test1("luo",29);
7、打开浏览器进行测试,输入地址http://localhost/nodepad/new%201.php
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:45
阅读量:44
阅读量:41
阅读量:45
阅读量:80