Jump to content

Zaxnyd

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Zaxnyd's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Answered my own Q much more quickly than I'd thought I would/could. So here's the answer for you curious readers. <?php class InputElement { var $customValidation; var $id; function InputElement($id){ $this->id = $id; } function validate(){ if(isset($this->customValidation)) return call_user_func($this->customValidation, $this); return "normal validation for ".$this->id; } } $input = new InputElement("input1"); echo $input->validate()."<br>\n"; echo "adding custom validation...<br>\n"; $input->customValidation = create_function('$obj', 'return "custom validation for ".$obj->id;'); echo $input->validate()."<br>\n"; ?> Outputs: normal validation for input1 adding custom validation... custom validation for input1
  2. I have a form class which offers basic default validation for each input method, but I'd like to be able to override the validate() function with any given logic (without re-writing the class each time). In javascript, it is possible to simply redeclare a function, such as inputElement.validate = function(){ return this.value != "invalid value"}; which would work like a freaking charm but alas PHP does not offer this syntax. Is there an equivalent or workaround that anyone knows of? I tried eval(), but it won't work, since it's impossible to access the object's variables from within the eval string. Thanks.
  3. Is it possible to output the line of some given code, particularly for debugging? Pseuso-code: showLine();//output 1 showLine();//output 2 showLine();//output 3 //etc...
  4. append_url = 'contact_info.php? Might be irrelevant, but I noticed this line needs a closing, like so: append_url = 'contact_info.php?';
  5. Solved it. It was the pesky plus sign that was doing it. So I just did an eregi_replace with a placeholder and it works wonderfully. Here's the class I made. Some of you might appreciate it: class url_serializable { function loadFromSerial($sSerial) { $urldecode = urldecode($sSerial); $urldecode = eregi_replace("--PLUS--", "\+", $urldecode); $base64_decode = base64_decode($urldecode); $unserialize = unserialize($base64_decode); return $this->loadFromObject($unserialize); } function sSerialized() { $sSerialized = $this; $sSerialized = serialize($sSerialized); $sSerialized = base64_encode($sSerialized); $sSerialized = eregi_replace("\+", "--PLUS--", $sSerialized); $sSerialized = urlencode($sSerialized); return $sSerialized; } }
  6. Solved it. It was the pesky plus sign that was doing it. So I just did an eregi_replace with a placeholder and it works wonderfully. Here's the class I made. Some of you might appreciate it: class url_serializable { function loadFromSerial($sSerial) { $urldecode = urldecode($sSerial); $urldecode = eregi_replace("--PLUS--", "\+", $urldecode); $base64_decode = base64_decode($urldecode); $unserialize = unserialize($base64_decode); return $this->loadFromObject($unserialize); } function sSerialized() { $sSerialized = $this; $sSerialized = serialize($sSerialized); $sSerialized = base64_encode($sSerialized); $sSerialized = eregi_replace("\+", "--PLUS--", $sSerialized); $sSerialized = urlencode($sSerialized); return $sSerialized; } }
  7. I'm looking for a failsafe way to send a serialized php object through AJAX. I posted <a href="http://www.phpfreaks.com/forums/index.php/topic,137636.0.html" target="_blank">my problem in the php section</a>, but haven't had a whole lot of luck there. Maybe you ajax pros have figured a way to do this. This is my failed attempt: (it works up until the data is passed via url, when it becomes corrupted) $serialize = serialize($myObject); $base64_encode = base64_encode($serialize); $urlencode = urlencode($base64_encode); //pass via Ajax / GET $urldecode = urldecode($urlencode ); $base64_decode = base64_decode($urldecode); $myObject= unserialize($base64_decode);
  8. I tried the ajax post method and the same conversion seems to occur.
  9. I had my encode/decode functions output the data at each stage of the transformation. I had it encode the data, then decoded it locally. Then it passed the data via URL to be decoded again. Most notable are the differences between the "As received" for the pre-pass and post-pass decodings. Encoding... this: Object id #6 serialize: O:10:"Classified":9:{s:2:"ID";s:1:"6";s:6:"userID";s:1:"1";s:4:"date";s:10:"0000-00-00";s:7:"listing";s:6:"Wanted";s:8:"category";s:8:"Antiques";s:7:"subject";s:7:"Testing";s:4:"body";s:191:" This is a p This is a list I am javascript ";s:8:"approved";N;s:5:"table";s:20:"wolfcreek_classified";} base64_encode: TzoxMDoiQ2xhc3NpZmllZCI6OTp7czoyOiJJRCI7czoxOiI2IjtzOjY6InVzZXJJRCI7czoxOiIxIjtzOjQ6ImRhdGUiO3M6MTA6IjAwMDAtMDAtMDAiO3M6NzoibGlzdGluZyI7czo2OiJXYW50ZWQiO3M6ODoiY2F0ZWdvcnkiO3M6ODoiQW50aXF1ZXMiO3M6Nzoic3ViamVjdCI7czo3OiJUZXN0aW5nIjtzOjQ6ImJvZHkiO3M6MTkxOiI8cD4gVGhpcyBpcyBhIHAgPC9wPg0KPHVsPg0KPGxpPlRoaXMgaXMgYSBsaXN0PC9saT4NCjwvdWw+DQo8c2NyaXB0Pg0KLy8gSGVyZSBpcyBzb21lICBqYXZhc2NyaXB0DQpkb2N1bWVudC53cml0ZSgnSSBhbSBqYXZhc2NyaXB0Jyk7DQo8L3NjcmlwdD4NCjxzdHlsZT4NCi5zaGVsbCB7DQpjb2xvcjojMEYwOw0KfQ0KPC9zdHlsZT4NCiI7czo4OiJhcHByb3ZlZCI7TjtzOjU6InRhYmxlIjtzOjIwOiJ3b2xmY3JlZWtfY2xhc3NpZmllZCI7fQ== urlencode TzoxMDoiQ2xhc3NpZmllZCI6OTp7czoyOiJJRCI7czoxOiI2IjtzOjY6InVzZXJJRCI7czoxOiIxIjtzOjQ6ImRhdGUiO3M6MTA6IjAwMDAtMDAtMDAiO3M6NzoibGlzdGluZyI7czo2OiJXYW50ZWQiO3M6ODoiY2F0ZWdvcnkiO3M6ODoiQW50aXF1ZXMiO3M6Nzoic3ViamVjdCI7czo3OiJUZXN0aW5nIjtzOjQ6ImJvZHkiO3M6MTkxOiI8cD4gVGhpcyBpcyBhIHAgPC9wPg0KPHVsPg0KPGxpPlRoaXMgaXMgYSBsaXN0PC9saT4NCjwvdWw%2BDQo8c2NyaXB0Pg0KLy8gSGVyZSBpcyBzb21lICBqYXZhc2NyaXB0DQpkb2N1bWVudC53cml0ZSgnSSBhbSBqYXZhc2NyaXB0Jyk7DQo8L3NjcmlwdD4NCjxzdHlsZT4NCi5zaGVsbCB7DQpjb2xvcjojMEYwOw0KfQ0KPC9zdHlsZT4NCiI7czo4OiJhcHByb3ZlZCI7TjtzOjU6InRhYmxlIjtzOjIwOiJ3b2xmY3JlZWtfY2xhc3NpZmllZCI7fQ%3D%3D -------------------------------------------------------------------------------- Decoding... As received: TzoxMDoiQ2xhc3NpZmllZCI6OTp7czoyOiJJRCI7czox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ojMEYwOw0KfQ0KPC9zdHlsZT4NCiI7czo4OiJhcHByb3ZlZCI7TjtzOjU6InRhYmxlIjtzOjIwOiJ3b2xmY3JlZWtfY2xhc3NpZmllZCI7fQ== base64_decode: O:10:"Classified":9:{s:2:"ID";s:1:"6";s:6:"userID";s:1:"1";s:4:"date";s:10:"0000-00-00";s:7:"listing";s:6:"Wanted";s:8:"category";s:8:"Antiques";s:7:"subject";s:7:"Testing";s:4:"body";s:191:" This is a p This is a list I am javascript ";s:8:"approved";N;s:5:"table";s:20:"wolfcreek_classified";} unserialize: Object id #22 -------------------------------------------------------------------------------- Pass via URL -------------------------------------------------------------------------------- Decoding... As received: TzoxMDoiQ2xhc3NpZmllZCI6OTp7czoyOiJJRCI7czoxOiI2IjtzOjY6InVzZXJJRCI7czoxOiIxIjtzOjQ6ImRhdGUiO3M6MTA6IjAwMDAtMDAtMDAiO3M6NzoibGlzdGluZyI7czo2OiJXYW50ZWQiO3M6ODoiY2F0ZWdvcnkiO3M6ODoiQW50aXF1ZXMiO3M6Nzoic3ViamVjdCI7czo3OiJUZXN0aW5nIjtzOjQ6ImJvZHkiO3M6MTkxOiI8cD4gVGhpcyBpcyBhIHAgPC9wPg0KPHVsPg0KPGxpPlRoaXMgaXMgYSBsaXN0PC9saT4NCjwvdWw+DQo8c2NyaXB0Pg0KLy8gSGVyZSBpcyBzb21lICBqYXZhc2NyaXB0DQpkb2N1bWVudC53cml0ZSgnSSBhbSBqYXZhc2NyaXB0Jyk7DQo8L3NjcmlwdD4NCjxzdHlsZT4NCi5zaGVsbCB7DQpjb2xvcjojMEYwOw0KfQ0KPC9zdHlsZT4NCiI7czo4OiJhcHByb3ZlZCI7TjtzOjU6InRhYmxlIjtzOjIwOiJ3b2xmY3JlZWtfY2xhc3NpZmllZCI7fQ== urldecode: TzoxMDoiQ2xhc3NpZmllZCI6OTp7czoyOiJJRCI7czoxOiI2IjtzOjY6InVzZXJJRCI7czoxOiIxIjtzOjQ6ImRhdGUiO3M6MTA6IjAwMDAtMDAtMDAiO3M6NzoibGlzdGluZyI7czo2OiJXYW50ZWQiO3M6ODoiY2F0ZWdvcnkiO3M6ODoiQW50aXF1ZXMiO3M6Nzoic3ViamVjdCI7czo3OiJUZXN0aW5nIjtzOjQ6ImJvZHkiO3M6MTkxOiI8cD4gVGhpcyBpcyBhIHAgPC9wPg0KPHVsPg0KPGxpPlRoaXMgaXMgYSBsaXN0PC9saT4NCjwvdWw DQo8c2NyaXB0Pg0KLy8gSGVyZSBpcyBzb21lICBqYXZhc2NyaXB0DQpkb2N1bWVudC53cml0ZSgnSSBhbSBqYXZhc2NyaXB0Jyk7DQo8L3NjcmlwdD4NCjxzdHlsZT4NCi5zaGVsbCB7DQpjb2xvcjojMEYwOw0KfQ0KPC9zdHlsZT4NCiI7czo4OiJhcHByb3ZlZCI7TjtzOjU6InRhYmxlIjtzOjIwOiJ3b2xmY3JlZWtfY2xhc3NpZmllZCI7fQ== base64_decode: unserialize:
  10. It's actually being passed via Ajax, so I don't think session would work. Is there no way to make a guaranteed URL-safe, string version of any given object without the corruption of loss of the serialized data?
  11. I'm passing an object of my own design.
  12. I need to serialize an object and pass it via URL. I've tried this, and many variations of it, but nothing seems to pass seemlessly in all cases: $sSerialized = serialize($myObj); $sSerialized = base64_encode($sSerialized); $sSerialized = urlencode($sSerialized); //pass via url, then on next page: $sSerialized = urldecode($sSerialized); $sSerialized = base64_decode($sSerialized); $myObj= unserialize($sSerialized); Seems like this should be a very easy thing to do, but I can't seem to get the hang of it. Thanks in advance.
  13. The answer was given in this thread: [url=http://www.phpfreaks.com/forums/index.php/topic,124051.0.html]http://www.phpfreaks.com/forums/index.php/topic,124051.0.html[/url]
  14. Is it possible to gather/output all of the method names within a class (particularly in php4)? seudocode: [code] class foo (   function1 {}   function2 {}   //soforth ) //desired result: // array("function1", "function2", soforth...); [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.