ranking Sort Sort   |   date Sort Sort   |   member Sort Sort

Date Submitted Mon. Jun. 4th, 2007 3:06 PM
Revision 1
Scripter Fordiman
Tags "object passing" | JavaScript | PHP | serialize
Comments 7 comments
This is a quick set of overrides for Javascript so that any variable can be passed to PHP in a GET/POST activity. Just call myVar.toPHP();

I use this little set of functions extensively in a little Javascript/PHP RPC handler I wrote. I don't have the reverse function, as I pass JSON back to the browser for the return value.

Note: This lib is not safe for binaries or HTML Elements. The former will come out similar to FTP ASCII breaks, and the latter will cause infinite recursion. If you want to make a speical case for HTML Elements, do so; you could probably just test for parentNode and create a 'safe' object from that. I didn't need it, so I didn't code it.

As for binary safety, at some point between toPHP/escape/post/urldecode/unserialize, the object breaks. Rather than create a huge fix for something I didn't need to do, I put in a quick match/hack. Don't like it? Write the fix yourself.