Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Questions about "static" and serialization [RSS Feed]

#1 Oct. 26, 2005 12:59:18

Matthias P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Questions about "static" and serialization


Hi internals,

I was experimenting with different approaches of maintaining state and
serializing objects in PHP5. The problem is handling static class
members and static variables inside methods.

First, I noted that static variables inside methods are shared between
instances. C++ seems to handle it the same way, but admittedly, I was a
little bit surprised: Such variables are available as "local" variables
in methods that are called using an instance, i. e. non-statically,
whereas static class variables can only be accessed using a static
reference to a class (self::, parent:: or Classname::).

However, this explains why static variables inside functions do not show
up when serializing object instances: Because the static variable is -
just like a static class variable - not "part of the object", but
belongs to the class.

So - has anybody ever considered serializing static variables as well?
Obviously they have to be treated separately at a per-class level; let
alone static variables in functions outside classes ;).

Would it be possible to write a session serialize handler that somehow
includes such static elements? I presume it should be possible to
"somewhere find" the static elements.

(Strictly spoken, an object instance's state expresses itself in
non-static members of the instance, so the above "static variables in
functions" stuff makes sense the way it is - if I want to maintain
per-instance state, I shouldn't be using local static variables, but
"plain" object members for that. However, when working with the
Singleton pattern, you don't come around using static at some level...)

Best regards,
Matthias

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Oct. 26, 2005 14:14:03

Wez F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Questions about "static" and serialization


As you mentioned, static properties and statically scoped variables
don't belong to an object instance, so it doesn't make sense to
serialize them.

--Wez.

On 10/26/05, Matthias Pigulla <> wrote:
> Hi internals,
>
> I was experimenting with different approaches of maintaining state and
> serializing objects in PHP5. The problem is handling static class
> members and static variables inside methods.
>
> First, I noted that static variables inside methods are shared between
> instances. C++ seems to handle it the same way, but admittedly, I was a
> little bit surprised: Such variables are available as "local" variables
> in methods that are called using an instance, i. e. non-statically,
> whereas static class variables can only be accessed using a static
> reference to a class (self::, parent:: or Classname::).
>
> However, this explains why static variables inside functions do not show
> up when serializing object instances: Because the static variable is -
> just like a static class variable - not "part of the object", but
> belongs to the class.
>
> So - has anybody ever considered serializing static variables as well?
> Obviously they have to be treated separately at a per-class level; let
> alone static variables in functions outside classes ;).
>
> Would it be possible to write a session serialize handler that somehow
> includes such static elements? I presume it should be possible to
> "somewhere find" the static elements.
>
> (Strictly spoken, an object instance's state expresses itself in
> non-static members of the instance, so the above "static variables in
> functions" stuff makes sense the way it is - if I want to maintain
> per-instance state, I shouldn't be using local static variables, but
> "plain" object members for that. However, when working with the
> Singleton pattern, you don't come around using static at some level...)
>
> Best regards,
> Matthias
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit:http://www.php.net/unsub.php>
>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 Oct. 26, 2005 22:20:09

Matthias P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Questions about "static" and serialization


> Von: Wez Furlong
>
> As you mentioned, static properties and statically scoped
> variables don't belong to an object instance, so it doesn't
> make sense to serialize them.

Ok, but on the other hand they are just variables - so the question was
if there is any (possibly userland) way to capture them in the line with
"normal" session handling, by using (un)serialize or whatever.

As to persisting and restoring structures like the singleton pattern, I
just noticed that the builtin serialization/persistence mechanisms don't
care about object identity at all... :(

Best regards,
Matthias

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] Questions about "static" and serialization [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support