Req #18018 [Opn->Fbk]: implement toJSON() method for objects and no header

From: Date: Tue, 02 Nov 2010 04:10:49 +0000
Subject: Req #18018 [Opn->Fbk]: implement toJSON() method for objects and no header
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-5015@lists.php.net to get a copy of this message
Edit report at http://pear.php.net/bugs/bug.php?id=18018&edit=1 ID: 18018 Updated by: alan@akbkhome.com Reported By: deusmax at gmail dot com Summary: implement toJSON() method for objects and no header -Status: Open +Status: Feedback Type: Feature/Change Request Package: Services_JSON Operating System: N/A Package Version: 1.0.2 PHP Version: 5.3.3 Roadmap Versions: New Comment: -Status: Open +Status: Feedback $x = new Services_JSON(); $x->encodeUnsafe($somevalue); I've just commited a patch for the other one. which implements it slightly differently. A) toJSON should return and array B) SERVICES_JSON_USE_TO_JSON must be used in the constructor. eg. $x = new Services_JSON(SERVICES_JSON_USE_TO_JSON); Regards Alan Previous Comments: ------------------------------------------------------------------------ [2010-11-01 12:46:40] deusmax Description: ------------ 1) It would be nice to be able to overide the default conversion for php objects, similar feature provided by JSON2 for javascript objects. The patch checks for the method of toJSON() to be asscocioted to the class. 2) Sometimes we want to encode without sending an html header. Added a parameter to method JSON::encode($phpVar, $sendHeader = true) The following patch implements both features 236c236 < function encode($var) --- > function encode($var, $sendHeader = true) 238c238,240 < header('Content-type: application/json'); --- > if ($sendHeader) { > header('Content-type: application/json'); > } 465a468,470 > if (in_array('toJSON', get_class_methods(get_class($var)))) { > return $var->toJSON(); > } ------------------------------------------------------------------------ -- Edit this bug report at http://pear.php.net/bugs/bug.php?id=18018&edit=1

« previous php.pear.bugs (#5015) next »