Basit bir PHP kodu Yorumlama

0 Cevap

Nesneyi önce değerleri değişiklikler kitapta verilen kod bloğunu takip yok ise bir veritabanı güncellenir Yıkıcıdan kavramını göstermek için:

<?php
  class use {
  private $_properties;
  private $_changedProperties //Keeps a list of the properties that were altered
  private $_hDB;

  //_construct and __get omitted for brevity

  function __set($propertyName, $value) {
     if(!array_key_exists($propertyName, $this->_properties))
     throw new Exception('Invalid property value!');

   if(method_exists($this, 'set'. $propertyName)) {
   return call_user_func(
                       array($this, 'set', $propertyName), $value);
    }
    else {
    //If the value of the property really has changed
    //and it's not already in the changedProperties array,
    //add it.

    if($this->_properties[$propertyName] !=$value && !in_array($propertyName,        $this->_changedProperties)) {
      $this->_changedProperties[] = $propertyName;
     }

Kodun geri kalanı gereksiz kod ve ihmal edilmiştir. Noktasından kodunu açıklayınız:

        if(method_exists($this, 'set'. $propertyName)) {
   return call_user_func(
                       array($this, 'set', $propertyName), $value);
    }
    else {
    //If the value of the property really has changed
    //and it's not already in the changedProperties array,
    //add it.

    if($this->_properties[$propertyName] !=$value && !in_array($propertyName, $this->_changedProperties)) {
      $this->_changedProperties[] = $propertyName;
     }

Neden ben bu soruyorum ben kod benim yorumlanması / anlayış doğrulamak istiyorum olmasıdır.

0 Cevap