53. 实体Entity(五)内容实体基类

龵龴龲龯龭龬龩龥龩龡龝龜龘龔龓龭龐龌龈龅龜龄龁龀齼齹齶齵齲齮齭齪齩drupal龓齘龘龜齖齓齪齹齒齏齋齊齆齂龜齀鼼齹齶齵齲齮龜龘齂鼸鼴鼲鼰鼬龓龩鼪鼨齹龌龈龅鼥鼤齂龜鼡鼞齹齏鼚鼗鼕齒龜鼓鼥鼏鼌齹鼊鼉龅鼅鼲鼂鼁黿鼥黽黹黷齹鼪黵黳齏黰黬黪黦黢黟點龘龜黚默鼰齩齖黖黖黓黒龈黎黌黋龜齹黊黈龜鼊鼉龅黆黄黀麽齒龜麻麷齹麵鼥黄黀齒龜麲麮麬齼齹鼓麫鼥鼪麧龜麤鼁齘麡麞齹龌龈龅麛麘齩齖黖黀麖龜齹麕齩麓麒麑黀黢黟麍麉黢麈麆麃麁麡麕黋齹麀鹽鹺麒鹹鹷黋鹴鹰齒鹮

齶齵齲齮齭齪鹬鹫麽齶齵齲齮龜鹪齏鼴鼲齹鹦齮龜齶齵齲齮鹤鹣齒鹡黆黳齏鹟鹛鹗麆龴鹖鼅鹒鹐齹麘鹎齶齵齲齮齪鹍齩鹊鹉鼅鹈鹅麮龜齹齶齵齲齮齪黆鹄鹂鸾齓鹈鹅鸻鸸鸵鹈鹅龜鸱鸰鸯鸭鼸鸫齹鸨鸧龵鸣鸟齹鸜鸘鸖齩鸒齖齓鹈鹅鸎鸒鸱鸰鸯鸭鸎齹鸊齭齪鼅麫鹉麘鸈鸣鸟鸅鸄龡龝齹鼪黽鸅鸄鸁龜齲齮鷿鸜鷾龩齖黌齹鼪鹐黀麽麫鷻鷷鷶鷲鷰鹮

鷷鷶鷲鷰鷭

鹉麽齋齊鸯鸭齀鼼齹齶齵齲齮齭齪鹒鹐麽齖鷪鹛鷨龜鷷鷶鷲鷰齹鼪齩鸊齪龜鹪齏鷥鷣鷠鷝齹黰黬麽鼪齓鷲鷰鷛鷙齊鷘鸊齭齪麽齹鹉鷔鷒鷎鹟麽鷋麒麮麆龴鹐麫鼊鼉龅鷇鷃鸊鷲鷰齹鼅麫鷀鼪齓鷲鷰鶽鶼齂齲鶹鶵鶴鶱鶰鷲鷰麍鶭齮鷲鷰麍龲鶫鷲鷰鶨鶨齹鶧鶥齩鶢齏龜齹鶞齊鶚齩鹪齏龜齹麆龴鷨鷻鷭

<?php
class yunke
{
    public $values = []; //用于存放变量
    public $activeLangcode = "en";  //当前语言
    public $defaultLangcode = "en"; //建立对象时的源语言
    public $translations; //各个翻译对象

    public function __construct($langcode = NULL)
    {
        if (empty($langcode)) {
            $langcode = "en";
        }
        $this->activeLangcode = $langcode;  //设置当前语言
        $this->defaultLangcode = $langcode; //标记源语言
    }

    public function get($key)
    {
        if (isset($this->values[$key][$this->activeLangcode])) {
            return $this->values[$key][$this->activeLangcode];
        }
        return isset($this->values[$key][$this->defaultLangcode]) ? $this->values[$key][$this->defaultLangcode] : NULL;
    }

    public function set($key, $value, $isTranslatable = true)
    {
        if ($isTranslatable) {
            $this->values[$key][$this->activeLangcode] = $value;
            if (!isset($this->values[$key][$this->defaultLangcode])) {
                $this->values[$key][$this->defaultLangcode] = $value;
            }
        } else {
            $this->values[$key][$this->defaultLangcode] = $value;
        }
        return $this;
    }

    public function getTranslation($langcode)
    {
        if (isset($this->translations[$langcode])) {
            return $this->translations[$langcode];
        }
        if ($langcode == $this->activeLangcode) {
            $this->translations[$langcode] = $this;
            return $this;
        }
        return $this->initializeTranslation($langcode);
    }

    public function initializeTranslation($langcode)
    {
        $translation = clone $this;
        $translation->values = &$this->values;
        $translation->translations = &$this->translations;
        $translation->activeLangcode = $langcode;
        $translation->defaultLangcode = &$this->defaultLangcode;
        $this->translations[$langcode] = $translation;
        return $translation;
    }

    public function getLangcode()
    {
        return $this->activeLangcode;
    }

    public function getOriginalLangcode()
    {
        return $this->defaultLangcode;
    }
}

$en = new yunke("en");
$en->set("msg", " English"); //首次建立后使用的语言产生的内容
echo $en->get("msg");

$zh_hans = $en->getTranslation("zh-hans"); //建立翻译对象
echo $zh_hans->get("msg");  //未进行人工翻译时默认使用原始语言的内容
$zh_hans->set("msg", "简体中文"); //对某语言进行人工翻译
echo $zh_hans->get("msg");
echo $en->getTranslation("zh-hans")->get("msg");
echo $zh_hans->getTranslation("en")->get("msg"); //可以通过任何一种语言得到其他语言

$zh_hans->set("untranslatableMsg", 1234, false); //在任意语言下均可设置不可翻译内容 
echo $en->get("untranslatableMsg"); //在任意语言下均可使用不可翻译内容

$fr = $zh_hans->getTranslation("fr");
echo $fr->get("untranslatableMsg"); //在任意语言下均可使用不可翻译内容
?>

鳉鳅龅鷥鳱鸊麆龴齹鳁鲽鼚鼗鼕鼪齓鷲鷰鹡鲺鲸鼊鼉齶齵齲齮齭齪齹鷻鲵黋黄黄鼪齓齭齪鹮

齶齵齲齮齭齪鷭

齶齵齲齮鲱鲭鴛齲齮齩drupal龜鲬龘齲齮齪鹍齹鲱鲭鴛齲齮齭齪齖麧齹齶齵齲齮齭齪齩鲨鲧鲣鲟龜齖齓鹐龥齶齵齲齮龜鲛鴶齭齪齹鹤鹣龡齲齮齭齪齹鹬鹫麽齶齵齲齮龜龘鸰龲鳣鹐鼴鼲齹鹦齮龜齶齵齲齮鲚鲚鼂鹤鹣鲗齹鼪麧鹟鹛鹗麆龴鹖鼅齹齪鲣鲟鲕鷻鷭
Drupal\Core\Entity\ContentEntityBase
鲵鲇鴺鴶oop龌龈鼰鲆鸊齩鲵鲇鹄鲅龜齹鹄鲅鲃鲂麽鱾鱽鴺鱻龜鱹鹐鱷鱳齹齩鱰鲣龜齹鹒鹐鱬鲵麘鱪鸜鱦齶鸰齲龐齹麽鷘鹄鲅齘龭齏齹鲱鲭鴛齲齮鱣鱢齶齵齲齮鱠黢黟黽齹鸊齭齪齲龐麽鲕鷻齂齓鹄鲅鷭
\IteratorAggregate
鱕鱔麈麆鱑鹄鲅齹php鶞鳸鲃鲂齹鱎鼤鱊齶齵齲齮鵆鶼鼸鱆齖麧黋鳵鳱鱅麬鱄鷣齹鷨鱁鰽鰹黰鹮
Drupal\Core\TypedData\TranslationStatusInterface
鸯鸭鰶鰵鹄鲅齹鲣鲟鲨鲧鱪齏龜麞鹗齹鲃鲂鰲鰮鹐龥鰬鰨齲齮龜鸯鸭龩鸾鸣鸟麆龴鷻龜鸯鸭鰶鰵
Drupal\Core\Entity\ContentEntityInterface
齶齵齲齮鹄鲅齹鰥鹐龥齶齵齲齮齹齩齖齓鰤鱔鹄鲅齹鰢鰞麽齶齵齲齮齹鹤鹣龡麫鷻鹄鲅鷭
Drupal\Core\Entity\FieldableEntityInterface
龘齂鼸齶齵齲齮齩齭龥鶥鷋鴺鴶龜齹鹡龅鰽鵆齲齮龜鶱鶰齹鰘鱦鳏鷔齋鰗龜鶥鷋鰓鰏鼸鸫鰋鰈龓龜鰄齹齖齓鶥鷋鴺鴶鼅麫鸨鸧齘齂齓鰄鰀鶥鷋鴺鴶鼅麫龲鷘鵜鵙龩鼸鸫鰋龓齹鸊鹄鲅鲃鲂鱣鸜鼴鼲齹鼪鲱鲭鴛齲齮龜鯿鵜鶞齊麘鸈齹鼅鶥鷋麮鯿鵜龜齶齵齲齮鴽鴻龩鯽鯼鲃鲂龜鶥鷋鱆鱽鯺鯸
Drupal\Core\Entity\RevisionableInterface
鸸鸵鼓鼥齶齵齲齮鳌鼅鯰鯭鹈鹅麮齹鯪麛鼅麫鸜鯩齹鸊鹄鲅鲃鲂鹈鹅麮鼴鼲
Drupal\Core\TypedData\TranslatableInterface
龩鲭鴛齲齮龓鳣龀鲭鴛鯦鹟黋齲龐鸯鸭鱣鸜龜鯤鯣齹鯪齶齵齲齮麘齖麧齹鼸鸫鹗點龘龜齂齹黳齏鯟鹐鯜鱻龜鯘鯗齹齲龐鸊鹄鲅麫齋齊鸯鸭鳪鷣
\Traversable
鼅鱅麬鲛鴶鹄鲅齹php鶞鳸鲃鲂齹鯖黰齶齵齲齮齩鼅鱅麬龜

龵鸣鸟Original language鷭
鸸鸵鯕鯒鷻齶齵齲齮齩鯰鯭鼅鸯鸭鼅鹈鹅麮龜齹麫鼌龬鹉鰄齹鯐齓鼌龬齶齵鼰鼅麫鼥齘齂齓鹈鹅齹鯐齓鹈鹅鼅麫鼥齘齂齓鸯鸭齹鯪鼪黽鸯鸭龓鯍鼥齖齓鷣鹉龵鸣鸟齹龩齼鯊龓鷀鹉鸸鸵鸣鸟齹鳟鳜鸯鸭鼰齩齭龥鸊龵鸣鸟龜鯈龩齶齵齪鹍龜鸣鸟鲭鴛鷷鴛龓齹麀鹽鼅麫鷷鴛鯇鴽鼌龬黵龵鸣鸟龜鸸鸵鯆鲱齩鹊鯂鯁鸣鸟鮿鮼鰈麑鮸齹鵆鯇鴽鼌龬龜鮷齖齓鹈鹅黵齹龩鱎鼤鯂鯁鸣鸟鮿鮼鱑龜鯕鯒鷻齹齶齵鮳鮰鮮鲵鼅麫鯖鲣龵鸣鸟齩鮫鮪齹鸊鹈鹅鮩麃龜鸯鸭鳌齩齭龥鸊龵鸣鸟龜齹鮩麃鸯鸭黵齶齵鮳鮰鮮鲵鮧鰮鮦鮥鸣鸟鮿鮸齹鮡鮞鲣鹉鮡鮩麃鸯鸭龜鸣鸟鰘鸊鮞鯗鼅鼲鱊黋鼂鮜鮚齹鷨 https://www.drupal.org/node/2443989 鰀齹龩龵鸣鸟鼓龩齶齵龜鮳鮰鮮鲵龵鸣鸟鼅麫鮐鮥齹鯪麘鼅鮐鮥鹉鮎鮩麃鸯鸭龜鸣鸟鯈龩鸊鹈鹅黪鳏齖齓鸯鸭鯸鳌鼅麫鯇鴽鹈鹅齹鯇鴽鹈鹅龜龵鸣鸟鸸鸵鹉鵂齖齓鹈鹅龜龵鸣鸟齹鯪鼪鼅麫鮐鮥齹鮐鮥鮌鮊鮇鮆齩麘鼲鹉鸊鹈鹅鮎鮃鵜龩龜鸯鸭齹龩鸊鹈鹅鯸鴺龵鸣鸟龜鮐鮥麘鮂鮀鵂齖齓鹈鹅龜龵鸣鸟鷷鴛齹龩鼸鸫鰋龓鹐魿魼鯆 default_langcode黋鯖鯁鹅鳱魸魷龜鸣鸟齩鹊鹉龵鸣鸟齹鹐魿魼鯆revision_translation_affected 鯖鯁鯇鴽龜鹈鹅龓鸾齓鸣鸟齩鹊鮎鮃鳵鳱龀鳭鳪鸯鸭齹鹐 content_translation_source 黋鯖鯁鹅鳱魸魷鸯鸭龡魵鷪鸣鸟齹齖魴鳌齩鹅鹈鹅龜龵鸣鸟齹鵆龵鸣鸟鮡鮐鮥鹡齹鸊鯆魰鯭麘鵗齹麘鼂魮鯺鮐鮥鯈龩鸾齓鹈鹅鯸魫魩鰏龵鸣鸟龜鸯鸭黵齹鯍魫魩鸊鹈鹅龜鸊鸯鸭齹麫鲚鹈鹅龜鸯鸭麘鹂鮂鮀鯈鯇鴽鹈鹅黵鼓鼥鸯鸭鳌鼂鯇鴽鹈鹅齹齶齵麓鵂齖齓鹈鹅龓鸊鸯鸭龜齶齵黢鯗齹麕麘齩鯇鴽鹈鹅黵鼓龩龜魵齓鸣鸟鹮
鼸鸫鰋鰈node魰鵜鼌龬龜鵆鵂鹈鹅鰘麛齩魥鯇鹈鹅鰀齹鳟龓龜langcode魰鵜鸊鹈鹅龜龵鸣鸟鯈鼅麫麓鼌龬鹈鹅鰈node_revision龓龜langcode黄黀鯐齓鹈鹅龜龵鸣鸟
鼥鲬鷪鱷魣龜鸣鸟麆龴鷭鸒und鸎鰈鯁鳷鯖鲣齹鸒zxx鸎鰈鯁麘魠鹐
龩齼鯊龓龵鸣鸟鰓麘麫鳟鸣鸟麆龴鰈鯁齹麕麫麞鹗Drupal\Core\Language\LanguageInterface::LANGCODE_DEFAULT鰈鯁齹鳟鯆鹉鸒x-default鸎


齶齵齲齮魚魖魔鼸魑鼸鷘魎鷭
$values鷭鸊魑鼸齩齖齓鼸鱆齹魰鵜魌齲齮鸾齓鹈鹅鰘黆鼲齩齖齓鰀龜鸱鸰鼸鸫齹鸨鸧鮡鸯鸭龜鼸鸫齹鸘鶧鹉鶥鷋鶧齹鷻齖魋鸘鶧鹉鸣鸟麆龴齹魮鹡鯆魉鸫鶥鷋龩鶵鶴鰈鸻鰥鹐鰈龓麻魚鼥魈魄鰘鷨齶齵齲齮鯿鵜齋齊鱑鹪鼼鰀
龩鶵鶴鰈龓鯿鵜龜鶥鷋麵鼥齂鯆齹鼓麫麵鼥鯆鷻鴘齹鸣鸟麆龴龜鷻齖魋鸘鶧鹉鶱鶰鶧鷭
$values[$field_name][$langcode][$property_name] =$value;
鲕麷鸊鶥鷋鯍鼥齖齓鶱鶰齹魵鮪鳵齖黖魁魀鶱鶰鶧鷭
$values[$field_name][$langcode] = $value;
龩鰥鹐鰈龓齖鬼鹉鷭
$values[$field_name][$langcode][$item][$property_name] = $value;
$item鹉鯆鷻鴘齹鯍鼥齖齓鯆魵鮪鹉0
鲕麷$langcode鹉龵鸣鸟齹魵鮪鸣鸟麆龴鹐LanguageInterface::LANGCODE_DEFAULT鰈鯁齹麕麘鹐龵鸣鸟龜鸣鸟麆龴鰈鯁

$translations鷭鹉齖齓鹺魔鼸array_keys鳻鳸龜鸨鬶鸣鸟麆龴龜鼸鱆鰘鲕array_keys($translations[$id])鰀齹鹐麫鯖鯁鸊鹈鹅齲齮鼥鬵黽鸣鸟鼥鸯鸭齹鳟龓鸸鸵鸣鸟鹐LanguageInterface::LANGCODE_DEFAULT鰈鯁

鶱鶰鰹黰鷭

$values麻魚鷭
$values[$key][$langcode]=$valus;齲齮鯆齹鬱鸣鸟鵜鵙齹龵鸣鸟龜鸣鸟麆龴鹐LanguageInterface::LANGCODE_DEFAULT鰈鯁齹麕麘齩龵鸣鸟龜鸣鸟麆龴齹鷨鯸鹮

$translations麻魚鷭
齩齖齓鼸鱆齹鸘鶧鹉鸣鸟麆龴齹鸘鯆鼅麫齩鼥鬭齓鬬鬫龜鼸鱆齹鲕鷻
$translations[$langcode][鸒status鸎]鰈黰龩鼪黽鸣鸟麆龴鯸龜鸯鸭鰶鰵鷭鯇鴽麍鵜龩麍鮎鬪魩
$translations[$langcode][鸒entity鸎]齩齖齓鹺鹅鴺鴶鸅鸄鸁黋龜鶵鶴齭鹅鶱鶰龜鸯鸭鴺鴶
$translations[$langcode]['status_existed']魿魼鯆齹鵆齲齮鴺鴶龓鵜龩龜鸯鸭鮡魫魩黵鹐龥鯖鯁鼸鸫鰋齩鹊黳齏鳵鳱魫魩鬤鷣

$translationInitialize
鰈黰齲齮齩鹊麡龩鬠鳱鸯鸭黊鳦麮齹麛鷛齩鬞麡鸅鸄鸯鸭鴺鴶齹鷷鴛鸊鵗鹗龜鷣鹐齩鬜鬛鸅鸄鸯鸭鴺鴶黵鬠鳱__clone()魔鼸

$langcodeKey
齲齮鴘鬖麮鸘鶧langcode鴺鲆龜鶥鷋鶧齹鲣鲟龩魎鳤龜entity_keys龓齹鲚鲚齩langcode齹鸊鶥鷋龩鼸鸫鰋龓鯿鵜齲齮鴺鲆龜鸣鸟麆龴

$defaultLangcodeKey
齲齮鴘鬖麮鸘鶧default_langcode鴺鲆龜鶥鷋鶧齹鲣鲟龩魎鳤龜entity_keys龓齹鲚鲚齩default_langcode齹龩鼸鸫鰋龓鸊鶥鷋鯿鵜齖齓魿魼鯆齹鰈黰齲齮鯿鵜龓鹅鬓鼸鸫鴺鲆龜鸣鸟齩鹊鷣鹉齲齮龵鸣鸟齹龩鸊鸣鸟鷻魫魩齲齮魵鮪鼓鼥鴺鲆龜鸯鸭鳌鼂鮡魫魩鹮

$activeLangcode
鵆鵂齲齮鴺鴶麆鰈龜鸣鸟麆龴齹鲕麷齖齓齲齮齩鼅鸯鸭龜鰘鹦鬐齂齓鸣鸟龜鰀齹魵鮪鵆鵂齲齮鱪麆鰈魌鳟龓齖鷪鸣鸟齹鼪鷛齩鸊鯆鯖鲣龜鸣鸟齹鲕麷鸊鸣鸟齩龵鸣鸟鮊鸊鯆鹐麞鹗LanguageInterface::LANGCODE_DEFAULT鰈鯁齹鸊麞鹗龜鯆鹉鷭'x-default'齹齲齮齲鶹麮鹡鹖麆鰈龵鸣鸟齹鳟鳜鸣鸟齲齮鴺鴶鳣龀黊鳦麮鸯鸭鸅鸄黿黀鹮

$defaultLangcode
魰鵜鵆鵂齲齮龜龵鸣鸟麆龴齹麛鷛齩 LanguageInterface::LANGCODE_DEFAULT鴺鲆鸣鸟龜麆龴齹龩齲齮鳵鳱鸯鸭鸅鸄黵齹$activeLangcode鮡鷷鴛鹉鸯鸭龜鸣鸟麆龴齹麕$defaultLangcode魰鯭麘鵗齹鼪鱎鼤鬎鬌鸾鸣鸟齩麓鬵齓鸣鸟鸯鸭龀黋龜鹮龩齲鶹麮齲齮黵龵鸣鸟龜鼸鸫齩麫LanguageInterface::LANGCODE_DEFAULT麆鬋鸣鸟麆龴鷣鹉鸘鶧鬊鹹龜齹鰲鰮setDefaultLangcode()鹐龥鷷鴛$defaultLangcode龜鯆齹龩魚魖魔鼸鬠鳱鬉鷋鱦鳏鷭
$this->translatableEntityKeys['langcode'][$this->activeLangcode]
龜鯆鷛齩龵鸣鸟麆龴齹鬇鹉鷔黵$this->activeLangcode龜鯆鹉LanguageInterface::LANGCODE_DEFAULT

$entityKeys
魰鵜魎鳤entity_keys鸘龓龜麘鼅鸯鸭龜鶱鶰齹齩齖齓鼸鱆齹鸘鶧鹉齲齮鴘鬖鸘鶧齹鬆龥鹒鹐齹鯆鹉鼸鸫鰋鯆齹

$translatableEntityKeys
魰鵜魎鳤entity_keys鸘龓鼅鸯鸭龜鶱鶰齹鯆鹉齖齓鼸鱆齹鸘鶧鹉齲齮鴘鬖鸘鶧齹鷻魋鸘鶧鹉鸣鸟麆龴齹鯆鹉鸊鸣鸟麆龴鷻鴺鲆龜鯆

$isDefaultRevision
鯖黰鵆鵂齲齮齩鹊齩鸸鸵鹈鹅齹鸸鸵鹈鹅鬄齩魥鯇龜鹈鹅鰘鹈鹅鬂髿鱄鷣齩麓齏鬂髿黀龜鹈鹅黢鯗鼸鸫髾鹫鯇龜鹈鹅鰀齹鸊鯆鰓麘麫黰鯂鰲鷰魰鵜龩鼸鸫鰋龓齹麕齩鹺鯿鵜齋齊鱑髻髺黿鸁齹鰓龩魑鼸$values龓鷷鴛鰘鹺鷔鼅鷨鸊魑鼸鯆鰓鰏鸱鸰黋龡鼸鸫鰋鰀齹魚魖魔鼸鼂鹉鸊鶱鶰髷鯆

鼸鸫鰋鱣鸜鶥鷋鰹黰鷭

revision_translation_affected鼸鸫鰋龓鸊鰄鯿鵜齖齓魿魼鯆齹鯖黰鹅鸣鸟龜鸯鸭齩鹊鮎鮃魮魌鯇鴽龜鹈鹅麕鮦鯇齹鯇鴽鹈鹅黵鼓龩龜魵齓鸣鸟鼂鮡鷷鴛鹉鬞齹鸸鸵鯕鯒鷻鯇鴽鹈鹅鹡齹鳟鳜鸣鸟鸯鸭齩黢鯗鵂齖齓鹈鹅鸊鸯鸭龓龜齶齵齹鲕麷麵鼥鮃龀鳭鳪鸯鸭鸊鯆鹉髶齹鬇鹉鯇鴽麽鹈鹅鯪鹅鸯鸭髴麵鼥鮦鯇齹鰹黰鯇鴽鹈鹅龜齶齵魈魄麵鼥齮龐龩鹅鸯鸭龓齹鲕麷鮃龀鸯鸭鮦鯇鸊鯆鹉鬞鹮

鸅鸄齲齮__clone鷭
php鸣鸟龓鸊髱髮鰲鰮龩鸅鸄鹡龜鯇鴺鴶鯸鱹鹐齹鳵鳱髪黢鯗齹鼨鲵龜$this鯖鯇鴺鴶鯈龩齶齵齲齮齭齪龓鸊鰲鰮鼨鲵鼥齘齂齪髩鲕鷻龜麆龴鷭

    $values = $this->values;
    $this->values = &$values;

鼪齩鬇鹉鸯鸭鴺鴶鯸鼪黽鶱鶰魰鵜龜齩黀龵鸣鸟鴺鴶鯸鸊鶱鶰龜髥鹐齹髢髞齒鹽龜鯆麘齩齖齓鴺鴶齹鯪鸅鸄黵髴齩麫髥鹐鬊髚齹髙鹐鯆黢鯗髕髺髥鹐黢鯗齹鼪麧齋齊鹡鼲魰髓麘齩髥鹐鬊髚齹鳉鷇鷃麫鷻麆龴鷭

class yunke
{
    public $var = 555;

    public function __clone()
    {
        $var = $this->var;
        $this->var =& $var; //该处是否加“&”结果不一样,加了为555,不加为666
    }

    public function getme()
    {
        $copy = clone $this;
        $copy->var =& $this->var;
        return $copy;
    }
}

$a = new yunke();
$b = $a->getme();
$c = clone $b;
$a->var = 666;
print_r($c);

龩鴺鴶鸅鸄龓鬠鳱髎髌龜髪黢鯗齹髥鹐鱊髋鹄黢鯗鹉髥鹐齹鹉麽鰹黰鼪龬鳉鲺黄麫鷻麆龴鷭

class yunke{
    public  $var=7;
}
$a=new yunke();
$b=new yunke();
$c=new yunke();

$b->var=&$a->var;
$c->var=$b->var; //后者虽是一个引用,但执行值复制
$d=clone $b; //后者中的var属性执行引用复制,
$a->var=8;
echo $c->var; //输出7
echo $d->var; //输出8

鱁鰽鰹黰鷭
1麍 鱕鱔麈麆鱑鹄鲅齹鷨php髀骼鳤骺鷭
http://php.net/manual/zh/class.iteratoraggregate.php


鹅鼌鷛黀鼪鼨齹鯪齶齵齲齮齭齪骶鳷鰗鹬齹鹺龥鳜鼬龓麽骴齂鼴鼲齹鹡骲鲨鰄鰗骯黖鰗鷘齹骭鱊鼂麉黢骪黄鸊齭齪龜齲龐齹鳣龀鹅鼌龜鹴鹰骧龩齊鷘黵鲆鸊麘齩黷黚麽

鷣龅鸣鷭

鵆齖齓鳭骦龩骢骡龜骝骛骙骘骔骑黵齹鷻鲵骦魌齖齓鸈麧骎骍魀鷔骔骑龜鳭齹骢骡齘骉齹鳜骎齏骆骄鯸鲸齹鼅齩骢骡鯸麵鼥骂齹鶭骁驽龜驺鰲麛麵鼥齹鼪齓黵驸鷻鲵龜鳭鼂齘驴驱齹驮驫驪驦齹鼪黵驸鳜鸊驢鮪驞驝驛齘齂鳭鰹drupal黷鼊齹鼪齩鬇鹉龩鼊鼉龀齼龓鷛鼂黈黀鼪鷪鯕鯒齹鷒鷎鱊鳟鷀鹉drupal龜鼊鼉骢骡齹龩鼊鼉黀齶齵齲齮黵鱊驘鹉鲕鷔齹鼪齓黵驸鳉麘齏驕驔龡龝齹驐鮆鼥鳭骄鯸鲸麽鷛齖鲣齩鼥骂龜齹鳭驌鳭鯺驊龜魈驉齩鼥鮞龜齹黆齏齂驈黵驊鷛鼲黰黬齹鸁龐骢骡鷻龜魵鷪驪驦齩鬇鹉黆黄黀麽麻麷齹麵鼥黄黀龀齼齹鼅鼲龩骢骡龜驆鲵鼥齖鬓驃驁龜骂齹鯸鲵龜鳭魉鹅麘齩麓骢骡騽鯸鲸龜鹮齶齵齲齮鷛齩鼪麧齹drupal龈黎驫騻骭黆鼂黄黀齖齓點龘黢黟龜鲨鲧齹齲齮魥黊黆齩齖齓齘麒麑龜鲨鲧鰘鷨鹅鲨鰄龜齲齮鹴鹰鰀齹魮鹡骯黖騸騷黌黋齹黳齏骭騴騴鮚麮齹齊鷘鳣鲇骢骡骝骛龜騱骂齹麘齏鮡鼊鼉骢骡騭黀鹮鼪鼨龲鶴齓騩黚齹龩鼸鼊騦鼥齓龘鶧騢騢龜黷鼼鶽鶼鸒騟騝龘鲣齊 鸎齹鼤齂鳭騜騚龩麡鲵骢骡龜骆騽鯸齹髋黀鬭騙齂騗鹡鼥齓鶽驕魼騕龜鳭龩鷇鷃騒騎騊騆黵鳏鱻髓黰麽鲗齹鲕鷔騂齊鹫駾齹龘駺鼅麫駷駵鷻鼪齓騩黚齹骂麘齩麵鼥齹黆齩黳齏駱駰鲱駬龲龜駩鯭鹮

本书共71小节:

评论 (写第一个评论)