English 中文(简体)
物体的序列化/航空化工作如何?
原标题:How does object serialize/unserialize work?

我正在读到PHP的序列化/统一概念。 我不知道它们是如何储存在档案系统/备份系统。 我认为这是以双向形式提出的。 然而,我想知道整个类别是如何储存的? 我的理解是,数据成员的数据可以储存,但储存的方法如何?

我指的是,PHP如何知道在言行中写什么法典?

$obj = new ClassName();
$obj->someFunc();
$serial = serialize($obj);
$unserialobj = unserialize($serial);
$unserialobj->someFunc();

PHP能够知道第2行将做些什么,但知道第5行将做些什么,而第5行是无意的? 这是否也拯救了该法典?

最佳回答

PHP can know what to do at line#2 but how it knows what to do at line#5 which is a unserialized object? does it save the code as well?

是的,serialize(>>)将节省有关该物体及其状态的类别的信息,因此,如果您不使用该类别的话,你就会获得该类别的例子,在这种情况下,该类别为。 类别Name

问题回答

When serializing an object, PHP only stores the object s current state, i.e. its property values. It does not serialize its methods. The corresponding class needs to be loaded in memory at the time of unserialization. PHP will restore the state of the object from the serialized string and take the rest of the information (structure and methods) from the class of the same name.

This is simple example to understand serialize and unserialize a object in php. we covert object into string using serialization and use this object current status (with assign values) after unserialization on other page..

c.php

<?php class A {
      public $one ;

      public function A($val) {
          $this->one=$val;
         // echo $this->one;
      }

      function display(){
        echo $this->one;
      }

  }
  ?> 

c.php a file have class with name A.
a.php

<? 
require_once "c.php";

$ob= new A( by Pankaj Raghuwanshi : Object Searlization. );

$ob->display(); // Output is: by Pankaj Raghuwanshi : Object Searlization.

$s = serialize($ob);

// echo $s will show  a string of an object

?>
<br><A href= b.php?s=<?=$s;?> >B-file</a>

我们用手法将这个物体编成雕像,然后通过该插图进入另一页。

Note :,我们可以将这一页数通过另一页,采用各种方法,如使用会议,我们可以节省到行文,并用另一页,但文本除外。

我们将在另一个档案名称(b.php)上将这个物体永久化。

b.php

<? 
require_once "c.php";

$ob = unserialize($_GET[s]);
$ob->display();
// Output is: by Pankaj Raghuwanshi : Object Searlization.
?> 

after unserialization, object showing same behavior like a.php file and assign value of a.php still is in memory of object . if we will unserialize this object after many http request . Object will persist all assign values in their memory.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签