mercredi 20 avril 2016

Mark class field

I am looking for a way to mark a field, and use that mark later for different operation on the object.

For example, serialize object without the marked fields:

class A(){
   public $field1;

   //@dont_serialize
   public $field2;
} 

$obj = new A();
$obj->field1 = "important data";
$obj->field2 = "not important data";

function MySerialize($obj){
  $arr = (array) $obj;
  $new_arr = array();   
  foreach ($arr as $key => $value) {
      if (THIS FEILD IS NOT MARKED AS @dont_serialize)
      {
        $new_arr[$key] = $value
      }
  }
  return serialize($new_arr);
}

How can I implement MySerialize() that will not serialize marked fields ?





Aucun commentaire:

Enregistrer un commentaire