npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

php-obj-deserializer

v0.1.4

Published

deserialize php objects to javascript objects

Readme

PHP Object Deserializer

Convert serialized PHP data to a javascript.

This fork

As the origin by bd808 was written in pure javascript I decided to rewrite using typescript.

Example

PHP:

$array = array(
  "foo" => "bar",
  "foobar" => "baz"
);
echo serialize($array);

JS/TS

import phpObjectDeserializer from "php-obj-deserializer";

const php_str = 'a:2:{s:3:\"foo\";s:3:\"bar\";s:6:\"foobar\";s:3:\"baz\";}'

phpObjectDeserializer(php_str)
  .then(console.log)
  .catch(console.error)

Result:

{ 
  foo:    'bar',
  foobar: 'baz' 
}

CommonJS

var phpObjDeserializer = require("php-obj-deserializer")

var php_str = 'a:2:{s:3:\"foo\";s:3:\"bar\";s:6:\"foobar\";s:3:\"baz\";}'

phpObjDeserializer.default()
  .then(console.log)
  .catch(console.error)

Anatomy of a PHP serialize()'ed value:

|Type|Anatomy|--| |--|--|--| |String|s:size:value;|String values are always in double quotes| |Integer|i:value;| |Boolean|b:value;|does not store true or false, does store 1 or 0| |Null|N;| |Array|a:size:{key;value;...}| key and value repeat for all elements. Array keys are always integers or strings| |Object|O:strlen(object_name):object_name:object_size:{s:strlen(property_name):property_name:property_definition;...}| strlen of property name, property_name and property_definition repeat for all properties in the object|

PHP Serialization Function Implementation Notes by the comunity:

"null => 'value'" equates to 's:0:"";s:5:"value";'
"true => 'value'" equates to 'i:1;s:5:"value";'
"false => 'value'" equates to 'i:0;s:5:"value";'

"array(whatever the contents) => 'value'" equates to an "illegal offset type" warning because you can't use an array as a key; however, if you use a variable containing an array as a key, it will equate to 's:5:"Array";s:5:"value";', and attempting to use an object as a key will result in the same behavior as using an array will.

Sources