首页 > 开发 > PHP > 正文

想学php5的来看看!!

2024-05-04 22:56:31
字体:
来源:转载
供稿:网友
  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • php代码:--------------------------------------------------------------------------------
    function factorymethod($class_type)
    {
    switch ($class_type)
    {
    case “foo”:
    $obj = new myfoo();
    break;
    case “bar”:
    $obj = new mybar();
    break;
    }
    return $obj;
    }
    $object = factorymethod(“foo”);

    $object->method()->method()

    $copy_of_object = $object->__clone();

    class myclass
    {
    function __destruct()
    {
    … // run destructor code
    }
    }


    delete $object;

    class shape {
    function __construct()
    {
    // shape initialization code

    }

    };


    class square extends shape
    {
    function __construct()
    {
    parent::__construct();
    // square-specific initialization code

    }

    };

    class foo
    {
    private $priv_var;
    function some_method(…)
    {
    $this->priv_var = …; // zend 上写的是:$priv_var = …; ,我没试过。
    }
    };

    class logger
    {
    static $m_instance = null;
    function instance()
    {
    if(logger::$m_instance == null)
    {
    logger::$m_instance = new logger();
    }
    return logger::$m_instance;
    }
    function log()
    {

    }
    };

    $logger = logger::instance();
    $logger->log(…);

    try
    {
    …code
    if (failure)
    {
    throw new myexception(“failure”);
    }
    …code
    }
    catch ($exception)
    {
    … handle exception
    throw $exception; // re-throw exception.
    }
    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表