免费邮箱 |加入收藏 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > PHP专区 > PHP教程

类与对象

时间:2011-05-16 16:00:42  来源:站内  作者:潘春会
Object {
        function
__construct( ) {
           
$n = func_num_args( ) ;
            for (
$i = 0 ; $i < $n ; $i += 2 ) {
               
$this->{func_get_arg($i)} = func_get_arg($i + 1) ;
            }
        }
    }

   
$o = new Object(
       
'aProperty', 'value',
       
'anotherProperty', array('element 1', 'element 2')) ;
    echo
$o->anotherProperty[1] ; // "element 2"
?>

You must feel free to make it better :)

spam at afoyi dot com (21-Mar-2005 09:18)

 

 

 

You can call a function defined in an inherited class from the parent class. This works in both PHP 4.3.6 and 5.0.0:

<?php

class p {
   
    function
p() {
        print
"Parent's constructorn";
    }
   
    function
p_test() {
        print
"p_test()n";
       
$this->c_test();
    }
}

class
c extends p {
   
    function
c() {
        print
"Child's constructorn";
       
parent::p();
    }
   
    function
c_test() {
        print
"c_test()n";
    }
}

$obj = new c;
$obj
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
如何找出DHCP地址池里未使用的IP地址
如何找出DHCP地址池里
国内常用的DNS列表
国内常用的DNS列表
Linux邮件服务器软件比较
Linux邮件服务器软件比
学用纯CSS打造可折叠树状菜单
学用纯CSS打造可折叠树
相关文章
栏目更新
栏目热门