function OjbToPHPArraySerialize() {
}
/* 
Returns the class name of the argument or undefined if 
it's not a valid JavaScript object. 
*/  
function getObjectClass(obj) {  
	if (obj && obj.constructor && obj.constructor.toString) {  
	var arr = obj.constructor.toString().match(  
		/function\s*(\w+)/);  
		if (arr && arr.length == 2) {
			return arr[1];  
		}  
	}  
	return undefined;  
}  
  
/* 
Serializes the given argument, PHP-style. 

The type mapping is as follows: 

JavaScript Type    PHP Type 
---------------    -------- 
Number             Integer or Decimal 
String             String 
Boolean            Boolean 
Array              Array 
Object             Object 
undefined          Null 

The special JavaScript object null also becomes PHP Null. 
This function may not handle associative arrays or array 
objects with additional properties well. Returns false when 
called with an argument that can't be represented in PHP. 
*/  
function phpSerialize(val) {  
	switch (typeof(val)) {  
		case "number":  
			if (val == NaN || val == Infinity) {  
				return false;  
			}  
			return (Math.floor(val) == val ? "i" : "d") + ":" +  val + ";";  
		case "string":  
			return "s:" + val.length + ":\"" + val + "\";";  
		case "boolean":  
			return "b:" + (val ? "1" : "0") + ";";  
		case "object":  
			if (val == null) {  
				return "N;";  
			} else if (val instanceof Array) {  
				var idxobj = { idx: -1 };  
				return "a:" + val.length + ":{" + val.map(  
					function (item) {  
						this.idx++;  
						var ser = phpSerialize(item);  
						return ser ?  phpSerialize(this.idx) + ser :  false;  
					}, idxobj).filter(  
						function (item) {  
						return item;  
					}).join("") + "}";  
			} else {  
				var class_name = getObjectClass(val);  
				if (class_name == undefined) {  
					return false;  
				}  
				var props = new Array();  
				for (var prop in val) {  
					var ser = phpSerialize(val[prop]);  
					if (ser) {  
						props.push(phpSerialize(prop) + ser);  
					}  
				}
				if (class_name == 'OjbToPHPArraySerialize'){
					return "a:" + props.length + ":{" +  props.join("") + "}";  
				} else {
					return "O:" + class_name.length + ":\"" +  class_name + "\":" + props.length + ":{" +  props.join("") + "}";  
				}
			}  
		case "undefined":  
			return "N;";  
	}  
	return false;  
}  
