NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
E_COMPILE_ERROR Declaration must be compatible ...


Joined: 24 Mar 2010
Posts: 49
Reply with quote
I irregulary receive the following error message ... i think generated by the DBG module of php. (It appears sometimes, after maybe some thousand executions, generated by Firefox's "reload every")

http ://www.kwicpix.de/display-i13866bpz7ln.html (plz. remove space after http)

executing the following test script and don't understand why MySecond::serialize() should be compatible with MySerializable::setUnserializedData, which are totally different functions at all. Maybe someone here has an idea?!

TIA Eutychus

Code:
<?php

trait MySerializable {

   public function serialize() {
      return serialize($this->getSerializeData());
   }

   public function unserialize($serialized) {
      $this->setUnserializedData(@unserialize($serialized));
   }

   /**
    * This method should return a data attributes of an object ...
    *
    * @return array
    */
   abstract protected function getSerializeData();

   abstract protected function setUnserializedData($data);

}

class MyFirst implements Serializable {

   use MySerializable;

   protected $firstVar = "hello";
   protected $secondVar = "world";
   protected $thirdVar = NULL;

   public function __construct() {
      $this->thirdVar = new MyThird();
   }

   protected function getSerializeData() {
      return [
         "firstVar" => $this->firstVar,
         "secondVar" => $this->secondVar,
         "thirdVar" => $this->thirdVar,
      ];
   }

   protected function setUnserializedData($data) {
      $this->firstVar = $data["firstVar"];
      $this->secondVar = $data["secondVar"];
      $this->thirdVar = $data["thirdVar"];
   }

}

class MySecond extends MyFirst {

   use MySerializable;

   protected $extended = "ext";

   protected function getSerializeData() {
      return array_merge(parent::getSerializeData(), [ "extended" => $this->extended ]);
   }

   protected function setUnserializedData($data) {
      parent::setUnserializedData($data);
      $this->extended = $data["extended"];
   }

}

class MyThird implements Serializable {

   use MySerializable;

   protected $thirdsVar = "BLUE";
   protected $thirdsSecondVar = NULL;

   protected function getSerializeData() {
      return [
         "thirdsVar" => $this->thirdsVar,
         "thirdsSecondVar" => $this->thirdsSecondVar,
      ];
   }

   protected function setUnserializedData($data) {
      $this->thirdsVar = $data["thirdsVar"];
      $this->thirdsSecondVar = $data["thirdsSecondVar"];
   }

}

session_set_save_handler("__open", "__close", "__read", "__write", "__destroy", "__gc");

function __open() {}

function __close() {}

function __destroy() {}

function __gc() {}

function __read($id) {
   return file_get_contents("test.session");
   return serialize([
      "first" => new MyFirst(),
      "second" => new MySecond(),
   ]);
}

function __write($id, $data) {
   file_put_contents("test.session", $data);
   echo $data."<br />\n";
}

session_name("ts");
session_start();

if ( empty($_SESSION) ) {
   $_SESSION["execCounter"] = 0;
   $_SESSION["first"] = new MyFirst();
   $_SESSION["second"] = new MySecond();
}
$_SESSION["execCounter"]++;

session_write_close();

?>
View user's profileFind all posts by eutychusSend private message
E_COMPILE_ERROR Declaration must be compatible ...
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic