色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP 的ArrayAccess接口 像數(shù)組一樣來訪問你的PHP對(duì)象

復(fù)制代碼 代碼如下:
interface ArrayAccess
boolean offsetExists($index)
mixed offsetGet($index)
void offsetSet($index, $newvalue)
void offsetUnset($index)

下面的例子展示了如何使用這個(gè)接口,例子并不是完整的,但是足夠看懂,:->
復(fù)制代碼 代碼如下:
<?php
class UserToSocialSecurity implements ArrayAccess
{
private $db;//一個(gè)包含著數(shù)據(jù)庫訪問方法的對(duì)象
function offsetExists($name)
{
return $this->db->userExists($name);
}
function offsetGet($name)
{
return $this->db->getUserId($name);
}
function offsetSet($name, $id)
{
$this->db->setUserId($name, $id);
}
function offsetUnset($name)
{
$this->db->removeUser($name);
}
}
$userMap = new UserToSocialSecurity();
print "John's ID number is " . $userMap['John'];
?>

實(shí)際上,當(dāng) $userMap['John'] 查找被執(zhí)行時(shí),php 調(diào)用了 offsetGet() 方法,由這個(gè)方法再來調(diào)用數(shù)據(jù)庫相關(guān)的 getUserId() 方法。

php技術(shù)PHP 的ArrayAccess接口 像數(shù)組一樣來訪問你的PHP對(duì)象,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 建宁县| 茶陵县| 莲花县| 德令哈市| 碌曲县| 威远县| 阿坝县| 台北县| 扶风县| 大荔县| 洛川县| 时尚| 仲巴县| 德惠市| 遵义县| 桃园县| 淮北市| 望城县| 介休市| 嫩江县| 嵩明县| 文安县| 新干县| 磐石市| 泰和县| 塘沽区| 新竹市| 邻水| 九龙坡区| 胶州市| 丰都县| 泗洪县| 阿图什市| 天镇县| 南丹县| 文成县| 远安县| 西安市| 景洪市| 平定县| 福建省|