Skip to content

Instantly share code, notes, and snippets.

@barhum

barhum/php Secret

Last active August 29, 2015 14:02
Show Gist options
  • Save barhum/cdc1d46111b0b3c14542 to your computer and use it in GitHub Desktop.
Save barhum/cdc1d46111b0b3c14542 to your computer and use it in GitHub Desktop.
php array
Failure/Error: customer.payment_methods << payment_method
NoMethodError:
undefined method `each_pair' for []:Array
# ./app/models/php_array.rb:11:in `new'
# ./app/models/php_array.rb:11:in `load'
# ./spec/api/order_spec.rb:345:in `block (3 levels) in <top (required)>
require 'ostruct'
require 'php_serialize'
class PhpArray < OpenStruct
class << self
def dump(obj)
::PHP.serialize(obj.attributes)
end
def load(s)
new(unserialize(s))
end
def unserialize arr
arr.blank? ? {} : ::PHP.unserialize(arr.encode('ASCII-8BIT',replace:"?"))
rescue Exception => e
Rails.logger.error e.message
Rails.logger.error e.backtrace.join("\n")
raise "Failed to unserialize #{arr.inspect}"
end
end
alias :attributes :marshal_dump
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment