Skip to content

Instantly share code, notes, and snippets.

@sbisbee
Created February 23, 2011 19:53
Show Gist options
  • Save sbisbee/841032 to your computer and use it in GitHub Desktop.
Save sbisbee/841032 to your computer and use it in GitHub Desktop.
A dirty piece of duct tape that converts a class into JSON.
#!/usr/bin/php
<?php
/*
* php2json
* by Sam Bisbee <sam@sbisbee.com>
* on 2011-02-23
*
* Takes in a class file, instantiates it, and then spits out its JSON.
*
* Example Usage: ./php2json.php UserVO.php
*/
$file = $argv[1];
require($file);
$class = substr($file, 0, strpos($file, '.php'));
echo json_encode(new $class)."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment