| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> php >> PHP gao ji OOP ji shu yan shi

PHP gao ji OOP ji shu yan shi

2008-12-19 08:07:52 编辑來源:互联网 评论
 
 
 
本文为【PHP高级OOP技术演示】的拼音翻译版
  zhai yao : zai ben wen zhong zuo zhe ji yu zi ji dui yu OOP gai nian de li jie , tong guo shi li xiang wo men zhan shi zi ji PHP zhong de duo zhong gao ji OOP ji shu , zheng ru zuo zhe suo yan “ xiang xiang shi wei yi de xian zhi ”
  ru guo ni le jie ji ben de OOP gai nian , na me wo jiang xiang ni zhan shi geng gao ji de ji shu 。
  xu lie hua (Serializing)
  PHP bu zhi chi yong jiu dui xiang , zai OOP zhong yong jiu dui xiang shi ke yi zai duo ge ying yong de yin yong zhong bao chi zhuang tai he gong neng de dui xiang , zhe yi wei zhe yong you jiang dui xiang bao cun dao yi ge wen jian huo shu ju ku zhong de neng li , er qie ke yi zai yi hou zhuang ru dui xiang 。 zhe jiu shi suo wei de xu lie hua ji zhi 。PHP yong you xu lie hua fang fa , ta ke yi tong guo dui xiang jin xing tiao yong , xu lie hua fang fa ke yi fan hui dui xiang de zi fu chuan biao shi 。 ran er , xu lie hua zhi bao cun le dui xiang de cheng yuan shu ju er bu bao hua fang fa 。
  zai PHP4 zhong , ru guo ni jiang dui xiang xu lie hua dao zi fu chuan $s zhong , ran hou shi fang dui xiang , jie zhe fan xu lie hua dui xiang dao $obj, ni ke yi ji xu shi yong dui xiang de fang fa ! wo bu jian yi zhe yang qu zuo , yin wei (a) wen dang zhong mei you bao zheng zhe zhong xing wei zai yi hou de ban ben zhong reng ran ke yi shi yong 。(b) zhe ge ke neng dao zhi yi zhong wu jie , zai ni ba yi ge xu lie hua hou de ban ben bao cun dao ci pan bing tui chu jiao ben shi 。 dang yi hou yun xing zhe ge jiao ben shi , ni bu neng qi dai zhe zai fan xu lie hua yi ge dui xiang shi , dui xiang de fang fa ye hui zai na li , yin wei zi fu chuan biao shi gen ben jiu bu bao kuo fang fa 。
  zong er yan zhi ,PHP jin xing xu lie hua dui yu bao cun dui xiang de cheng yuan bian liang fei chang you yong 。( ni ye ke yi jiang xiang guan shu zu he shu zu xu lie hua dao yi ge wen jian zhong )。
  li zi :
  <?php
  $obj=new Classfoo();
  $str=serialize($obj);
   // bao cun $str dao ci pan shang
  // ji ge yue yi hou
  // cong ci pan zhong zhuang ru str
   $obj2=unserialize($str)
  ni hui fu le cheng yuan shu ju , dan shi bu bao kuo fang fa ( gen ju wen dang suo shuo )。 zhe dao zhi le zhi neng tong guo lei si yu shi yong $obj2->x lai cun qu cheng yuan bian liang ( ni mei you bie de fang fa !) de wei yi ban fa , suo yi bu yao zai jia li shi ta 。
  you yi xie ban fa ke yi jie jue zhe ge wen ti , wo ba ta liu zhe , yin wei dui zhe pian jian jie de wen zhang lai shuo , ta men tai bu hao 。 wo hui hen gao xing di huan ying zai PHP de hou xu ban ben zhong you quan xu lie hua de te xing 。
  shi yong lei jin xing shu ju cun chu PHP he OOP yi jian fei chang hao de shi qing jiu shi , ni ke yi hen rong yi di ding yi yi ge lei lai cao zuo mou jian shi qing , bing qie wu lun he shi ni xiang yong de shi hou dou ke yi tiao yong xiang ying de lei 。 jia she ni you yi ge HTML biao dan , yong hu ke yi tong guo xuan ze chan pin ID hao lai xuan ze yi ge chan pin 。 zai shu ju ku zhong you chan pin de xin xi , ni xiang ba chan pin xian shi chu lai , xian shi ta de jia ge deng deng 。 ni yong you bu tong lei xing de chan pin , bing qie tong yi ge dong zuo ke neng dui bu tong de chan pin ju you bu tong de yi si 。 li ru , xian shi yi ge sheng yin ke neng yi wei zhe bo fang ta , dan shi dui yu qi ta zhong lei de chan pin ke neng yi wei zhe xian shi yi ge cun zai shu ju ku zhong de tu pian 。 ni ke yi shi yong OOP huo PHP lai jian shao bian ma bing ti gao zhi liang 。
  ding yi yi ge chan pin de lei , ding yi ta ying gai you de fang fa ( li ru : xian shi ), ran hou ding yi dui mei yi zhong lei xing de chan pin de lei , cong chan pin lei pai hou chu lai (SoundItem lei ,ViewableItem lei , deng deng ), fu gai zai chan pin lei zhong de fang fa , shi ta men an ni de xiang fa dong zuo 。
  gen ju shu ju ku zhong mei yi zhong chan pin de lei xing (type) zi duan gei lei ming ming , yi ge dian xing de chan pin biao ke neng you (id, type, price, description, deng deng zi duan )... ran hou zai chu li jiao ben zhong , ni ke yi cong shu ju ku zhong qu chu type zhi , ran hou shi li hua yi ge ming wei type de dui xiang :
  <?php
  $obj=new $type();
  $obj->action();
  zhe shi PHP de yi ge fei chang hao de te xing , ni ke yi bu yong kao lv dui xiang de lei xing , tiao yong $obj de xian shi fang fa huo qi ta de fang fa 。 shi yong zhe ge ji shu , ni bu xu yao xiu gai jiao ben qu zeng jia yi ge xin lei xing de dui xiang , zhi shi zeng jia yi ge chu li ta de lei 。
  zhe ge gong neng hen qiang da , zhi yao ding yi fang fa , er bu qu kao lv suo you dui xiang de lei xing , zai bu tong de lei zhong an bu tong de fang fa shi xian ta men , ran hou zai zhu jiao ben zhong dui ren yi dui xiang shi yong ta men , mei you if...else, ye bu xu yao liang ge cheng xu yuan , zhi you gao xing 。
  xian zai ni tong yi bian cheng shi rong yi de , wei hu shi bian yi de , ke chong yong shi zhen de ma ?
  ru guo ni guan li yi zu cheng xu yuan , fen pei gong zuo jiu shi hen jian dan de le , mei ge ren ke neng fu ze yi ge lei xing de dui xiang he chu li ta de lei 。
  ke yi tong guo zhe ge ji shu shi xian guo ji hua , gen ju yong hu suo xuan de yu yan zi duan ying yong xiang ying de lei jiu ke yi le , deng deng 。
  kao bei he ke long
  dang ni chuang jian yi ge $obj de dui xiang shi , ni ke yi tong guo $obj2=$obj lai kao bei dui xiang , xin de dui xiang shi $obj de yi ge kao bei ( bu shi yi ge yin yong ), suo yi ta ju you $obj zai dang shi de zhuang tai 。 you shi hou , ni bu xiang zhe yang , ni zhi shi xiang sheng cheng yi ge xiang obj lei yi yang de yi ge xin de dui xiang , ke yi tong guo shi yong new yu ju lai tiao yong lei de gou zao han shu 。 zai PHP zhong ye ke yi tong guo xu lie hua , he yi ge ji lei lai shi xian , dan suo you de qi ta lei dou yao cong ji lei pai sheng chu lai 。
  jin ru wei xian qu yu
  dang ni xu lie hua yi ge dui xiang , ni hui de dao mou zhong ge shi de zi fu chuan , ru guo ni gan xing qu , ni ke yi tiao jiu ta , qi zhong , zi fu chuan zhong you lei de ming zi ( tai hao le !), ni ke yi ba ta qu chu lai , xiang :
  <?php
  $herring=serialize($obj);
  $vec=explode(':',$herring);
  $nam=str_replace("\"",'',$vec[2]);
  suo yi jia she ni chuang jian le yi ge "Universe" de lei , bing qie qiang zhi suo you de lei dou bi xu cong universe kuo zhan , ni ke yi zai universe zhong ding yi yi ge clone de fang fa , ru xia :
  <?php
  function clone() {
  $herring=serialize($this);
  $vec=explode(':',$herring);
  $nam=str_replace("\"",'',$vec[2]);
  $ret=new $nam;
  return $ret;
  }
  }
  // ran hou
  $obj=new Something();
  // cong Universe kuo zhan
  $other=$obj->clone();
  ni suo de dao de shi yi ge xin de Something lei de dui xiang , ta tong shi yong new fang fa , tiao yong gou zao han shu chuang jian chu de dui xiang yi yang 。 wo bu zhi dao zhe ge dui ni shi fou you yong , dan shi Universe lei ke yi zhi dao pai sheng lei de ming zi shi yi ge hao de jing yan 。 xiang xiang shi wei yi de xian zhi 。
  zhe ge yu ju jiu shi xie ru dang qian de shi jian 。【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
zhai yao : zai ben wen zhong zuo zhe ji yu zi ji dui yu OOP gai nian de li jie , tong guo shi li xiang wo men zhan shi zi ji PHP zhong de duo zhong gao ji OOP ji shu , zheng ru zuo zhe suo yan “ xiang xiang shi wei yi de xian zhi ” ru guo ni le jie ji ben de OOP gai nian , na me wo jiang xiang ni zhan shi geng gao ji de ji shu 。 xu lie hua (Serializing) PHP bu zhi chi yong jiu dui xiang , zai OOP zhong yong jiu dui xiang shi ke yi zai duo ge ying yong de yin yong zhong bao chi zhuang tai he gong neng de dui xiang , zhe yi wei zhe yong you jiang dui xiang bao cun dao yi ge wen jian huo shu ju ku zhong de neng li , er qie ke yi zai yi hou zhuang ru dui xiang 。 zhe jiu shi suo wei de xu lie hua ji zhi 。PHP yong you xu lie hua fang fa , ta ke yi tong guo dui xiang jin xing tiao yong , xu lie hua fang fa ke yi fan hui dui xiang de zi fu chuan biao shi 。 ran er , xu lie hua zhi bao cun le dui xiang de cheng yuan shu ju er bu bao hua fang fa 。 zai PHP4 zhong , ru guo ni jiang dui xiang xu lie hua dao zi fu chuan $s zhong , ran hou shi fang dui xiang , jie zhe fan xu lie hua dui xiang dao $obj, ni ke yi ji xu shi yong dui xiang de fang fa ! wo bu jian yi zhe yang qu zuo , yin wei (a) wen dang zhong mei you bao zheng zhe zhong xing wei zai yi hou de ban ben zhong reng ran ke yi shi yong 。(b) zhe ge ke neng dao zhi yi zhong wu jie , zai ni ba yi ge xu lie hua hou de ban ben bao cun dao ci pan bing tui chu jiao ben shi 。 dang yi hou yun xing zhe ge jiao ben shi , ni bu neng qi dai zhe zai fan xu lie hua yi ge dui xiang shi , dui xiang de fang fa ye hui zai na li , yin wei zi fu chuan biao shi gen ben jiu bu bao kuo fang fa 。 zong er yan zhi ,PHP jin xing xu lie hua dui yu bao cun dui xiang de cheng yuan bian liang fei chang you yong 。( ni ye ke yi jiang xiang guan shu zu he shu zu xu lie hua dao yi ge wen jian zhong )。 li zi : <?php $obj=new Classfoo(); $str=serialize($obj); // bao cun $str dao ci pan shang // ji ge yue yi hou // cong ci pan zhong zhuang ru str   $obj2=unserialize($str) ni hui fu le cheng yuan shu ju , dan shi bu bao kuo fang fa ( gen ju wen dang suo shuo )。 zhe dao zhi le zhi neng tong guo lei si yu shi yong $obj2->x lai cun qu cheng yuan bian liang ( ni mei you bie de fang fa !) de wei yi ban fa , suo yi bu yao zai jia li shi ta 。 you yi xie ban fa ke yi jie jue zhe ge wen ti , wo ba ta liu zhe , yin wei dui zhe pian jian jie de wen zhang lai shuo , ta men tai bu hao 。 wo hui hen gao xing di huan ying zai PHP de hou xu ban ben zhong you quan xu lie hua de te xing 。 shi yong lei jin xing shu ju cun chu PHP he OOP yi jian fei chang hao de shi qing jiu shi , ni ke yi hen rong yi di ding yi yi ge lei lai cao zuo mou jian shi qing , bing qie wu lun he shi ni xiang yong de shi hou dou ke yi tiao yong xiang ying de lei 。 jia she ni you yi ge HTML biao dan , yong hu ke yi tong guo xuan ze chan pin ID hao lai xuan ze yi ge chan pin 。 zai shu ju ku zhong you chan pin de xin xi , ni xiang ba chan pin xian shi chu lai , xian shi ta de jia ge deng deng 。 ni yong you bu tong lei xing de chan pin , bing qie tong yi ge dong zuo ke neng dui bu tong de chan pin ju you bu tong de yi si 。 li ru , xian shi yi ge sheng yin ke neng yi wei zhe bo fang ta , dan shi dui yu qi ta zhong lei de chan pin ke neng yi wei zhe xian shi yi ge cun zai shu ju ku zhong de tu pian 。 ni ke yi shi yong OOP huo PHP lai jian shao bian ma bing ti gao zhi liang 。 ding yi yi ge chan pin de lei , ding yi ta ying gai you de fang fa ( li ru : xian shi ), ran hou ding yi dui mei yi zhong lei xing de chan pin de lei , cong chan pin lei pai hou chu lai (SoundItem lei ,ViewableItem lei , deng deng ), fu gai zai chan pin lei zhong de fang fa , shi ta men an ni de xiang fa dong zuo 。 gen ju shu ju ku zhong mei yi zhong chan pin de lei xing (type) zi duan gei lei ming ming , yi ge dian xing de chan pin biao ke neng you (id, type, price, description, deng deng zi duan )... ran hou zai chu li jiao ben zhong , ni ke yi cong shu ju ku zhong qu chu type zhi , ran hou shi li hua yi ge ming wei type de dui xiang : <?php $obj=new $type(); $obj->action(); zhe shi PHP de yi ge fei chang hao de te xing , ni ke yi bu yong kao lv dui xiang de lei xing , tiao yong $obj de xian shi fang fa huo qi ta de fang fa 。 shi yong zhe ge ji shu , ni bu xu yao xiu gai jiao ben qu zeng jia yi ge xin lei xing de dui xiang , zhi shi zeng jia yi ge chu li ta de lei 。 zhe ge gong neng hen qiang da , zhi yao ding yi fang fa , er bu qu kao lv suo you dui xiang de lei xing , zai bu tong de lei zhong an bu tong de fang fa shi xian ta men , ran hou zai zhu jiao ben zhong dui ren yi dui xiang shi yong ta men , mei you if...else, ye bu xu yao liang ge cheng xu yuan , zhi you gao xing 。 xian zai ni tong yi bian cheng shi rong yi de , wei hu shi bian yi de , ke chong yong shi zhen de ma ? ru guo ni guan li yi zu cheng xu yuan , fen pei gong zuo jiu shi hen jian dan de le , mei ge ren ke neng fu ze yi ge lei xing de dui xiang he chu li ta de lei 。 ke yi tong guo zhe ge ji shu shi xian guo ji hua , gen ju yong hu suo xuan de yu yan zi duan ying yong xiang ying de lei jiu ke yi le , deng deng 。 kao bei he ke long dang ni chuang jian yi ge $obj de dui xiang shi , ni ke yi tong guo $obj2=$obj lai kao bei dui xiang , xin de dui xiang shi $obj de yi ge kao bei ( bu shi yi ge yin yong ), suo yi ta ju you $obj zai dang shi de zhuang tai 。 you shi hou , ni bu xiang zhe yang , ni zhi shi xiang sheng cheng yi ge xiang obj lei yi yang de yi ge xin de dui xiang , ke yi tong guo shi yong new yu ju lai tiao yong lei de gou zao han shu 。 zai PHP zhong ye ke yi tong guo xu lie hua , he yi ge ji lei lai shi xian , dan suo you de qi ta lei dou yao cong ji lei pai sheng chu lai 。 jin ru wei xian qu yu dang ni xu lie hua yi ge dui xiang , ni hui de dao mou zhong ge shi de zi fu chuan , ru guo ni gan xing qu , ni ke yi tiao jiu ta , qi zhong , zi fu chuan zhong you lei de ming zi ( tai hao le !), ni ke yi ba ta qu chu lai , xiang : <?php $herring=serialize($obj); $vec=explode(':',$herring); $nam=str_replace("\"",'',$vec[2]); suo yi jia she ni chuang jian le yi ge "Universe" de lei , bing qie qiang zhi suo you de lei dou bi xu cong universe kuo zhan , ni ke yi zai universe zhong ding yi yi ge clone de fang fa , ru xia : <?php function clone() { $herring=serialize($this); $vec=explode(':',$herring); $nam=str_replace("\"",'',$vec[2]); $ret=new $nam; return $ret; } } // ran hou $obj=new Something(); // cong Universe kuo zhan $other=$obj->clone(); ni suo de dao de shi yi ge xin de Something lei de dui xiang , ta tong shi yong new fang fa , tiao yong gou zao han shu chuang jian chu de dui xiang yi yang 。 wo bu zhi dao zhe ge dui ni shi fou you yong , dan shi Universe lei ke yi zhi dao pai sheng lei de ming zi shi yi ge hao de jing yan 。 xiang xiang shi wei yi de xian zhi 。 zhe ge yu ju jiu shi xie ru dang qian de shi jian 。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
清凉一夏_清纯美丽
纯白色小礼服
靓丽可人儿_嘉嘉
我的女神_靓丽女生
主题摄影
贵州,让我欢喜,让我神伤。
莫干山
天平秋色
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有