def PHP.serialize_session(var, assoc = false)
s = ''
case var
when Hash
var.each do |key,value|
if key.to_s =~ /\|/
raise IndexError, "Top level names may not contain pipes"
end
s << "#{key}|#{PHP.serialize(value, assoc)}"
end
when Array
var.each do |x|
case x
when Array
if x.size == 2
s << "#{x[0]}|#{PHP.serialize(x[1])}"
else
raise TypeError, "Array is not associative"
end
end
end
else
raise TypeError, "Unable to serialize sessions with top level types other than Hash and associative Array"
end
s
end