php中的类有什么用?和自定义函数有什么区别?

来源:百度知道 编辑:UC知道 时间:2024/07/04 03:49:59
php中的类有什么用?和自定义函数有什么区别?能举例最好~!
可以继承是什么意思??

请看PHP手册18章,里面的内容你看了就明白。

第 18 章 类与对象(PHP 4)
目录

继承
构造函数
范围解析操作符(::)
parent
序列化对象 - 会话中的对象
魔术函数 __sleep 和 __wakeup
构造函数中的引用
对象的比较



类是变量与作用于这些变量的函数的集合。使用下面的语法定义一个类: 

<?php
class Cart {
    var $items;  // 购物车中的物品

    // 将 $num 个 $artnr 物品加入购物车

    function add_item($artnr, $num) {
        $this->items[$artnr] += $num;
    }

    // 将 $num 个 $artnr 物品从购物车中取出

    function remove_item($artnr, $num) {
        if ($this->items[$artnr] > $nu