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

类与对象

时间:2011-05-16 16:00:42  来源:站内  作者:潘春会

Table of Contents


<script language="JavaScript1.2" src="_notes_script.js" type="text/javascript"></script>

用户评论:

suleman dot saleh at gmail dot com (26-Oct-2010 02:41)

 

 

 

Using php abstract classes we must have to implement all their functions in child classes other wise it will make automatically child class as a concrete

DavMe (01-Oct-2010 03:03)

 

 

 

When you have a class name in a variable and want to create a new instance of that class, you can simply use:
<?php
$className
= "ClassName";
$instance = new $className();
?>

If, however, you have a class that is part of a singleton pattern where you cannot create it with new and need to use:
<?php
$instance
= ClassName::GetInstance();
?>

...you quickly discover that it fails miserably with a variable.
Fail Example:
<?php
$className
= "ClassName";
$instance = $className::GetInstance();
?>

After a few days of head pounding, I finally put together this workaround:
<?php
$className
= "ClassName";
eval(
'$instance = '.$className
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
如何找出DHCP地址池里未使用的IP地址
如何找出DHCP地址池里
国内常用的DNS列表
国内常用的DNS列表
Linux邮件服务器软件比较
Linux邮件服务器软件比
学用纯CSS打造可折叠树状菜单
学用纯CSS打造可折叠树
相关文章
栏目更新
栏目热门