これは、いくつかのphp関数を介してオブジェクトを渡している状況です。私は最高のパフォーマンスを探しているので、シリアル化はそれを行うための良い方法なのか、それともシリアル化は必要ないのか疑問に思っていましたか?
4 に答える
Just pass the object. You don't need serialization.
function foo() {
return new Foo;
}
function bar($obj) {
return $obj;
}
function baz($obj) {
$obj->foo();
}
baz(bar(foo()));
If you are passing an object through several 'functions' then you don't need to serialise - this will be in memory in the PHP parser and serialization will just be a waste.
If you need to pass the value from one script page to another, then serialization is an option as the variables in the first script will be out of scope in the second script.
Most of the time you don't need to do this - what exactly are you trying to do?
次のようにオブジェクトを渡すのに問題はないと思います。
$obj=new myclass;
$result=mufunk($obj);
function myfunk($myfobj)
{
$myreturn=new anotherclass;
return $myreturn;
}
Serialization is one of the worst things you can do. Objects in php 5 are passed by reference and this way the amount of data passed between functions is minimal(only a pointer which is an integer).