Desktop Online

So I have a new idea, it is an online desktop where you can organize files visually very much similar to a regular desktop except through a web browser.

I was kinda inspired by this idea after working in google docs and being able to drag and drop a picture from my desktop right into the document. Also Picasa uses the same technology (imagine that!) for uploading pictures.

Thinking of possibilities for this application it seems like quite a simple idea (which I say for every project), but would be modular in a way that you could drag and drop to a variety of backend repositories. Some of these would include: Google docs, Dropbox, an FTP server, and perhaps a network drive or a remote computer (with additional software of course).

This would be an extensive project, but I think the idea is solid and would be very useful to extend upon existing cloud file sharing, archiving, synchronizing technologies that present current data in lists of directories and files. This would simply allow for a more intuitive method of organization.

Will I pursue this project? Probably not, that is unless Google, or Dropbox called me up and asked me to. Then sure!

Edit: It now exists, welcome otixo.com

PHP Static Class Variable

Recently found out that when you serialize a class (in my case it was storing it in a $_SESSION[] variable)  that the class’s static variable gets reset to it’s default value. Consider the following:

  1. (page) script runs
  2. class constructed
  3. class used (static variable set)
  4. class serialized at end of script (automatically when stored in a $_SESSION[] variable)
  5. (new/next page) different or same script runs
  6. class deserialized (automatically by referencing you $_SESSION[] variable)
  7. !static variable is default!

This doesn’t mean what you set it to in the constructor, since the constructor doesn’t get called when an object is deserialized. Rather when you declare the variable in the class. For example:

Class User{
	private  static $loggedIn = 0;
}

So if you do not declare a default value, then your variable will simply be ‘unset’ when you reference your freshly deserialized class object.

A solution? Here is where the __magic begins!

So if the static variable isn’t preserved then you must use the magic php class functions __destruct() and __wakeup(). Consider the following, where you want to preserver whether a single user is logged in or not:

Class User{
	private  static $loggedIn = 0;
	private $thisLoggedIn;

	function isUserLoggedIn(){
		return self::$loggedIn;
	}

	function __destruct() {
		$this->thisLoggedIn = self::$loggedIn;
	}

	public function __wakeup(){
		self::$loggedIn = $this->thisLoggedIn;
	}
}

Here is what happens:

I always store and use the instance of the User class from a $_SESSION[‘user’] variable, this is important because any changes I make to the object is preserved after the script terminates and the object is serialized.

So you will see that in the destructor we have:

$this->thisLoggedIn = self::$loggedIn;

This way, at the end of the page script the destructor is called. We set the private variable $thisLoggedIn as what our static variable $loggedIn is. The importance of this is that the value of ‘self::$loggedIn’ is preserved as ‘$this->thisLoggedIn’ when the object gets serialized.

Then when the object is automatically deserialiezed, the magic php function ‘__wakeup()’ is automatically called. In this we reset the static variable to what was serialized and stored inbetween page transitions in the  $_SESSION[‘user’] variable.

The only thing that you must be sure of now is that besides in the ‘__destruct()’ and ‘__wakeup()’ calls, never use ‘$thisLoggedIn’ anywhere in the class. Always reference the static variable ‘self::$loggedIn’. That way you can be sure that what you are storing and then restoring is what your expecting.